Now on Omarchy: read the manual without leaving your desktop

Cheat Sheet

The commands you keep forgetting, with a one-line description and a real example you can copy - 629 across 38 tools. Pick a tool in the sidebar, or search across all of them.

Showing React Hooks. Choose another tool in the sidebar, or search all 629 commands.

React Hooks

Hook signatures, the rules, and which hook fits which job.

18 commands
CommandWhat it doesExample
useStateLocal state: value + setter; setter triggers re-render.const [count, setCount] = useState(0)
functional updateWhen new state depends on old - always safe.setCount(c => c + 1)
state: new referencesNever mutate - copy, then set.setItems([...items, newItem])
useEffect (mount)Run once after first render - empty deps.useEffect(() => { document.title = "Shop"; }, [])
useEffect (on change)Re-run when a dependency changes.useEffect(() => { fetchUser(id).then(setUser); }, [id])
useEffect cleanupReturn a function to undo what you started.useEffect(() => { const t = setInterval(tick, 1000); return () => clearInterval(t); }, [])
useRef (DOM)A handle to an element - focus, measure, scroll.const inputRef = useRef(null); inputRef.current?.focus()
useRef (mutable box)Persists across renders WITHOUT re-rendering.const renders = useRef(0); renders.current++
useMemoCache an expensive computed value by deps.const sorted = useMemo(() => [...rows].sort(byDate), [rows])
useCallbackStable function identity for memoized children.const onSave = useCallback(() => save(id), [id])
useContextRead the value from the nearest provider above.const theme = useContext(ThemeContext)
useReducerMany update rules, one dispatch.const [state, dispatch] = useReducer(reducer, initial)
custom hookPackage reactive logic as use-prefixed function.function useDebounce(value, ms) { /* useState + useEffect inside */ }
rules of hooksTop level only - never in ifs, loops, or callbacks.const [x, setX] = useState(0); if (loading) return <Spinner />
list keysStable identity per item - never index on mutable lists.items.map(i => <Row key={i.id} item={i} />)
controlled inputValue from state, keystrokes into state.<input value={email} onChange={e => setEmail(e.target.value)} />
pass the functiononClick={fn} runs on click; onClick={fn()} runs NOW.<button onClick={() => remove(id)}>Delete</button>
which hook whenDerived value: useMemo (or just compute). Side effect: useEffect. Shared: useContext. DOM: useRef.const total = items.reduce((s, i) => s + i.price, 0) // no hook needed