Gist 782553a6e275e4bfc694a6a3a6d1a46f
✓ Published0🌍 Public
HHuyAms
Last edited Sep 10, 2019
Created on Sep 10, 2019
This example demonstrates how the React `useRef` hook preserves a mutable value across re-renders, unlike the `createRef` API, which creates a new ref each render. It visually compares the two by displaying the current render index alongside the persisted value from `useRef` and the reset value from `createRef` after a button click triggers a state update. The code uses `React.useState` to drive re-renders and `React.useRef` to hold a stable reference, while `createRef` shows its transient nature. The example also uses `useEffect` with a custom comparison to illustrate deep object dependency handling, referencing the React documentation.
AI-generated description