{"version":"1.0","type":"rich","title":"A hook that persists useState() to localStorage.","description":"This example demonstrates a custom React hook that synchronizes a component’s state with the browser’s localStorage, enabling persistent data across page reloads. The hook, `useStateStorage`, initializes state with a provided default value and reads any stored JSON from localStorage on mount, updating the state if valid. It exposes a setter function that writes both the new state and its JSON-serialized form to localStorage. The code uses React’s `useState`, `useEffect`, and `useCallback` APIs to manage lifecycle and memoization, while leveraging `localStorage.getItem` and `localStorage.setItem` for storage operations.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-a175db091f8779af614f6b62a7d339af?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}