{"version":"1.0","type":"rich","title":"Hook that emits the previous and current values of useState()","description":"This example demonstrates a React hook that tracks both the previous and current values of a state variable, returning them as a pair for comparison or animation. The `useStatePair` hook initializes with an undefined previous value and the provided initial state, then uses a `setPair` callback to update the tuple whenever `setValue` is called. It relies on React’s `useState` and `useCallback` APIs to manage the state pair and memoize the update function, ensuring stable references. The code shows a generic pattern for observing state transitions without additional libraries.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-bba96542d60a2723eb26cc1e144c6c17?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}