To automatically update (re-render) a React component when the browser window changes size, you listen for the resize event on window, store the size in component state, and update that state inside an effect—triggering a re-render.
Track Window Dimensions 🖥️
Listen for Resize Events 🎧
Cleanup to Prevent Leaks 🧹
Return a cleanup function from useEffect that removes the listener:
Ensures you don’t accumulate multiple listeners if the component mounts/unmounts.
Debounce for Performance (Optional) ⏱️