In my Learn React Hooks workshop material, we have an exercise where we build a tic-tac-toe game using React’s useState hook (based on the official React tutorial). Here’s the Github file for the finished version of that exercise We have ...

If you’ve been working with React for a while, you’ve probably used useState. Here’s a quick example of the API: function Counter() { const [count, setCount] = React.useState(0) const increment = () => setCount(count + 1) return <button onClick={increment}>{count}</button> } ...

I made a useDarkMode hook that looks like this: type DarkModeState = 'dark' | 'light' type SetDarkModeState = React.Dispatch<React.SetStateAction<DarkModeState>> function useDarkMode() { const preferDarkQuery = '(prefers-color-scheme: dark)' const [mode, setMode] = React.useState<DarkModeState>(() => { const lsVal = window.localStorage.getItem('colorMode') if (lsVal) ...