Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Global State in React: The Limits of Context, Zustand and When to Use Redux Toolkit
Most "global state" is really server, URL or form state; for the small client state that is truly global, Zustand's store with selectors fixes Context's render-every-reader problem, while Redux Toolkit comes in when you need an action log and rules for a large team. In Bookstore we move the recently viewed books and the cart id into a persisted store, and show reading without selectors causing 13 renders instead of 1 and a selector returning a new object looping forever in Zustand 5.
useRef, Context and Custom Hooks: DOM Access, Context Instead of DI and the Rules of Hooks
useRef is a box that does not trigger renders (a DOM node or a timer id), while Context carries a value deep into the tree without props and re-renders every component that reads it when it changes. We move the Bookstore cart, theme and user into Context, measure a version where a theme change renders 28 components instead of 2, and show an inline ref callback stealing focus, a conditional hook crashing the app and the search split into custom hooks.