### Install @react-hookz/web with yarn Source: https://github.com/react-hookz/web/blob/master/README.md Use this command to install the library using yarn. ```shell yarn add @react-hookz/web ``` -------------------------------- ### Install @react-hookz/web with npm Source: https://github.com/react-hookz/web/blob/master/README.md Use this command to install the library using npm. ```shell npm i @react-hookz/web ``` -------------------------------- ### Running Storybook Watch Source: https://github.com/react-hookz/web/blob/master/CONTRIBUTING.md Start Storybook in watch mode to preview your hook documentation locally. ```shell yarn storybook:watch ``` -------------------------------- ### useList Example for Todo List Source: https://github.com/react-hookz/web/blob/master/_autodocs/STATE_HOOKS.md Illustrates managing a list of todos using the useList hook, including adding, updating, and deleting items. ```typescript function TodoList() { const [todos, actions] = useList([ { id: 1, text: 'Learn hooks', done: false }, ]); return (
{todos.map((todo) => (
actions.updateAt( todos.indexOf(todo), { ...todo, done: !todo.done } ) } /> {todo.text}
))}
); } ``` -------------------------------- ### useCustomCompareEffect Example Source: https://github.com/react-hookz/web/blob/master/_autodocs/LIFECYCLE_HOOKS.md This example demonstrates how to use useCustomCompareEffect with a custom dependency comparator. The effect will only re-run if the stringified previous and next config objects are different, preventing unnecessary re-renders. ```typescript function ConfigComponent({ config }) { useCustomCompareEffect( () => { console.log('Config updated'); applyConfig(config); }, [config], (prev, next) => { // Deep comparison of config objects return JSON.stringify(prev[0]) === JSON.stringify(next[0]); } ); return
Config applied
; } ``` -------------------------------- ### Example Usage of useQueue Hook Source: https://github.com/react-hookz/web/blob/master/_autodocs/STATE_HOOKS.md Demonstrates how to use the useQueue hook to manage a list of tasks, allowing users to add, process, and clear tasks. ```typescript function TaskProcessor() { const [tasks, actions] = useQueue(['task1', 'task2']); const processNext = () => { const task = actions.remove(); if (task) { console.log('Processing', task); } }; return (

Queue size: {tasks.length}

); } ``` -------------------------------- ### Example Usage of useAsyncAbortable Source: https://github.com/react-hookz/web/blob/master/_autodocs/SIDE_EFFECT_AND_SENSOR_HOOKS.md Demonstrates how to use the useAsyncAbortable hook to fetch data with cancellation support. It shows how to execute the search, display loading states, and cancel the request. ```typescript function SearchWithCancel({ query }) { const [results, actions, meta] = useAsyncAbortable( async (signal: AbortSignal, searchTerm: string) => { const response = await fetch(`/api/search?q=${searchTerm}`, { signal, }); return response.json(); } ); useEffect(() => { if (query) { actions.execute(query); } }, [query, actions]); return (
{results.status === 'loading' && ( <>
Searching...
)} {results.status === 'success' && ( )}
); } ``` -------------------------------- ### useMap Hook Example Source: https://github.com/react-hookz/web/blob/master/_autodocs/STATE_HOOKS.md Demonstrates how to use the useMap hook to manage a Map state with automatic re-renders on mutations. It allows adding, deleting, and displaying entries. ```typescript function CacheViewer() { const cache = useMap([['key1', 'value1']]); return (
); } ``` -------------------------------- ### useDebouncedState Example Source: https://github.com/react-hookz/web/blob/master/_autodocs/STATE_HOOKS.md Demonstrates how to use useDebouncedState to debounce search input, fetching results only after the user stops typing for a specified delay. ```typescript function SearchInput() { const [searchTerm, setSearchTerm] = useDebouncedState('', 300); const [results, setResults] = useState([]); useEffect(() => { if (searchTerm) { fetch(`/api/search?q=${searchTerm}`) .then(r => r.json()) .then(setResults); } }, [searchTerm]); return (
setSearchTerm(e.target.value)} placeholder="Search..." />
); } ``` -------------------------------- ### useDeepCompareMemo Example Source: https://github.com/react-hookz/web/blob/master/_autodocs/STATE_HOOKS.md Illustrates using useDeepCompareMemo to memoize the result of an expensive computation based on a configuration object. It ensures recomputation only when the configuration's content deeply changes, not just its reference. ```typescript function ComplexComponent({ config }) { const memoizedValue = useDeepCompareMemo( () => { return expensiveComputation(config); }, [config] // Even if config object reference changes, equality check detects same content ); return
{memoizedValue}
; } ``` -------------------------------- ### Control Video Playback with Visibility Source: https://github.com/react-hookz/web/blob/master/_autodocs/SIDE_EFFECT_AND_SENSOR_HOOKS.md This example demonstrates how to use the useDocumentVisibility hook to control video playback. It pauses the video when the document is hidden and resumes it when visible. ```typescript function VideoPlayer() { const visibility = useDocumentVisibility(); useEffect(() => { const video = document.querySelector('video'); if (video) { if (visibility === 'hidden') { video.pause(); } else if (visibility === 'visible') { video.play(); } } }, [visibility]); return