Separate hook instances and contracts
Each call has its own state
Reusing the same Hook definition does not merge the state of its callers. React associates state with the component instance and the position of its Hook calls. Even two calls inside one component have separate state. Use an owner component or context when independent callers actually need a shared value.
import React, { useState } from 'react';function useToggle(initial = false) { const [open, setOpen] = useState(initial); return {open, toggle: () => setOpen(v => !v)};}export default function App() { const packing = useToggle(true); const route = useToggle(false); return <main><button aria-expanded={packing.open} onClick={packing.toggle}>Packing</button> {packing.open && <p>Water and notebook</p>} <button aria-expanded={route.open} onClick={route.toggle}>Route</button> {route.open && <p>Follow the marked path.</p>}</main>;}Packing starts open; Route starts closed. Activating Route does not close Packing. Two uses of the same function share code, not state. When both panels need exactly one active item, lift that decision into App instead of trying to synchronize two separate Hooks.
Define a useful contract
import React, { useState } from 'react';function normalizeNote(text) { return text.trim(); }/** @param {string} initialText * @returns {{text: string, cleaned: string, setText: (value: string) => void, reset: () => void}} */function useDraftNote(initialText) { const [text, setText] = useState(initialText); return {text, cleaned: normalizeNote(text), setText, reset: () => setText(initialText)};}export default function App() { const note = useDraftNote('Oak trail'); return <main><label>Trail note <input value={note.text} onChange={e => note.setText(e.target.value)} /></label> <p>Preview: {note.cleaned || '(empty)'}</p><button onClick={note.reset}>Reset note</button></main>;}The input keeps the spaces you type; the preview removes outer whitespace. Reset restores the supplied initialText from the current render. Passing a different initialText later does not automatically replace existing state. The JSDoc contract describes a string input and named fields, not a runtime type validator. Derive cleaned during render instead of storing a second synchronized value.
Compose small Hooks with a named purpose
import React, { useState } from 'react';function useToggle(initial = false) { const [on, setOn] = useState(initial); return [on, () => setOn(v => !v)];}function useNoteEditor() { const [text, setText] = useState(''); const [preview, togglePreview] = useToggle(); return {text, setText, preview, togglePreview};}export default function App() { const editor = useNoteEditor(); return <main><label>Note <textarea value={editor.text} onChange={e => editor.setText(e.target.value)} /></label> <button aria-expanded={editor.preview} onClick={editor.togglePreview}>Preview</button> {editor.preview && <p>{editor.text || '(empty)'}</p>}</main>;}The preview shows the same text without a second copy in state. useNoteEditor calls useToggle unconditionally. Its returned handlers are ordinary functions; this implementation does not promise stable function identity. If the behavior is used only once and extraction makes the component harder to read, keep it in the component. Practice: add a second editor instance and verify neither note changes when the other is edited.