Tiny React Hooks
A quick note containing a tiny hook example and reactivity mindset.
Hook example
import { useState, useEffect } from "react";
function useWindowWidth() {
const [width, setWidth] = useState(window.innerWidth);
useEffect(() => {
const handleResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
return width;
}
Keep hooks small and focused. This example is a useful reminder that many utility hooks can be reused across notes and UI components.