KS
Killer-Skills

compose-hooks — how to use compose-hooks how to use compose-hooks, compose-hooks setup guide, compose-hooks alternative, compose-hooks vs ahooks, compose-hooks install, what is compose-hooks, compose-hooks react style hooks, jetpack compose state management, compose multiplatform hooks

v1.0.0
GitHub

About this Skill

Perfect for Android and Multiplatform Agents needing simplified state management with Jetpack Compose and Compose Multiplatform. compose-hooks is a Hooks library for Compose Multiplatform, inspired by React Hooks and ahooks, designed to simplify state management.

Features

Provides `useState` hook for basic state management
Offers `useGetState` hook for destructured state management
Includes `useBoolean` hook for boolean state management
Supports `rememberXxx` aliases for all `useXxx` functions
Enables easier state management with React style hooks

# Core Topics

junerver junerver
[0]
[0]
Updated: 3/7/2026

Quality Score

Top 5%
39
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add junerver/ComposeHooks/references/request-hooks.md

Agent Capability Analysis

The compose-hooks MCP Server by junerver is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use compose-hooks, compose-hooks setup guide, compose-hooks alternative.

Ideal Agent Persona

Perfect for Android and Multiplatform Agents needing simplified state management with Jetpack Compose and Compose Multiplatform.

Core Value

Empowers agents to manage state with React-style hooks, utilizing libraries like ComposeHooks and ahooks, and supporting features such as useState, useGetState, and useBoolean for efficient state handling.

Capabilities Granted for compose-hooks MCP Server

Simplifying state management in Jetpack Compose applications
Implementing boolean state management with useBoolean
Optimizing state updates with useGetState and useState

! Prerequisites & Limits

  • Requires Jetpack Compose or Compose Multiplatform setup
  • Limited to Kotlin-based projects
Project
SKILL.md
6.0 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

ComposeHooks 使用指南

ComposeHooks 是一个为 Jetpack Compose/Compose Multiplatform 设计的 Hooks 库,灵感来自 React Hooks 和 ahooks。

核心概念

所有 useXxx 函数都有对应的 rememberXxx 别名,选择你喜欢的命名风格。

快速参考

状态管理 Hooks

Hook用途示例
useState基础状态管理(推荐用 by 委托)var state by useState("")
useGetState解构使用的状态管理(推荐)val (state, setState, getState) = useGetState(0)
useBoolean布尔状态管理val (state, toggle, setValue, setTrue, setFalse) = useBoolean(false)
useReducerRedux 风格状态管理val (state, dispatch) = useReducer(reducer, initialState)
useRef不触发重组的引用val ref = useRef(0)
useList列表状态管理val list = useList(1, 2, 3)
useMapMap 状态管理val map = useMap("key" to "value")

副作用 Hooks

Hook用途示例
useEffect副作用处理useEffect(dep) { /* effect */ }
useMount组件挂载时执行useMount { loadData() }
useUnmount组件卸载时执行useUnmount { cleanup() }
useUpdateEffect跳过首次执行的 EffectuseUpdateEffect(dep) { /* effect */ }

网络请求

Hook用途示例
useRequest网络请求管理val (data, loading, error, request) = useRequest(requestFn)

工具 Hooks

Hook用途示例
useDebounce防抖值val debouncedValue = useDebounce(value)
useThrottle节流值val throttledValue = useThrottle(value)
useInterval定时器useInterval { tick() }
useTimeoutFn延时执行useTimeoutFn(fn, 1.seconds)
useUndo撤销/重做val (state, set, reset, undo, redo) = useUndo(initial)

详细参考

常见模式

1. 受控组件

kotlin
1// 推荐:使用 useGetState 解构 2val (text, setText) = useGetState("") 3OutlinedTextField( 4 value = text.value, 5 onValueChange = setText, 6 label = { Text("输入") } 7) 8 9// 或使用 by 委托 10var text by useState("") 11OutlinedTextField( 12 value = text, 13 onValueChange = { text = it }, 14 label = { Text("输入") } 15)

2. 解决闭包问题(来自 UseStateExample.kt)

kotlin
1// 方式1: 使用 useGetState 函数式更新 2val (state, setState) = useGetState("initial") 3LaunchedEffect(Unit) { 4 repeat(10) { 5 delay(1.seconds) 6 setState { "$it." } // 函数式更新,避免闭包问题 7 } 8} 9 10// 方式2: 使用 by 委托 11var byState by useState("initial") 12LaunchedEffect(Unit) { 13 repeat(10) { 14 delay(1.seconds) 15 byState += "." // 直接修改,无闭包问题 16 } 17} 18 19// 方式3: 使用 useLatestRef 20val (state, setState) = useState("initial") 21val stateRef = useLatestRef(state) 22LaunchedEffect(Unit) { 23 repeat(10) { 24 delay(1.seconds) 25 setState("${stateRef.current}.") // 通过 ref 获取最新值 26 } 27}

3. 网络请求(来自 Auto&Manual.kt)

kotlin
1// 自动请求 2val (userInfoState, loadingState, errorState) = useRequest( 3 requestFn = { NetApi.userInfo(it) }, 4 optionsOf = { 5 defaultParams = "junerver" // 自动请求必须设置默认参数 6 } 7) 8val userInfo by userInfoState 9val loading by loadingState 10 11if (loading) { 12 Text(text = "loading ...") 13} 14userInfo?.let { Text(text = it.toString()) } 15 16// 手动请求 17val (repoInfoState, loadingState, errorState, request) = useRequest( 18 requestFn = { it: Tuple2<String, String> -> 19 NetApi.repoInfo(it.first, it.second) 20 }, 21 optionsOf = { 22 manual = true 23 defaultParams = tuple("junerver", "ComposeHooks") 24 } 25) 26TButton(text = "request") { request() }

4. Redux 风格状态管理(来自 UseReducerExample.kt)

kotlin
1// 定义 State 和 Action 2data class SimpleData(val name: String, val age: Int) 3 4sealed interface SimpleAction { 5 data class ChangeName(val newName: String) : SimpleAction 6 data object AgeIncrease : SimpleAction 7} 8 9// 定义 Reducer 10val simpleReducer: Reducer<SimpleData, SimpleAction> = { prevState, action -> 11 when (action) { 12 is SimpleAction.ChangeName -> prevState.copy(name = action.newName) 13 is SimpleAction.AgeIncrease -> prevState.copy(age = prevState.age + 1) 14 } 15} 16 17// 使用 18val (state, dispatch) = useReducer( 19 simpleReducer, 20 initialState = SimpleData("default", 18), 21 middlewares = arrayOf(logMiddleware()) 22) 23 24TButton(text = "Change Name") { dispatch(SimpleAction.ChangeName("Alice")) } 25TButton(text = "Increase Age") { dispatch(SimpleAction.AgeIncrease) } 26Text(text = "State: ${state.value}")

5. 列表操作(来自 UseListExample.kt)

kotlin
1val listState = useList(1, 2, 3) 2 3// 操作方法 4listState.add(4) // 添加 5listState.add(0, 0) // 插入 6listState.removeAt(0) // 删除 7listState.removeLast() // 删除最后一个 8listState[0] = 10 // 修改 9listState.clear() // 清空 10listState.shuffle() // 打乱 11 12// 配合 useListReduce 13val sum by useListReduce(listState) { a, b -> a + b }

6. 防抖输入(来自 UseDebounceExample.kt)

kotlin
1var inputValue by useState("") 2val debouncedValue by useDebounce( 3 value = inputValue, 4 optionsOf = { 5 wait = 500.milliseconds 6 } 7) 8 9OutlinedTextField( 10 value = inputValue, 11 onValueChange = { inputValue = it }, 12 label = { Text("Type something...") } 13) 14 15Text(text = "Debounced: $debouncedValue")

Related Skills

Looking for an alternative to compose-hooks or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication