3 ms·
Most of this is solid advice, but I disagree with some of the `useRef` stuff. Refs are an escape hatch for things that can't be modeled with React's existing re
by spoiler 2y ago
Most of this is solid advice, but I disagree with some of the `useRef` stuff. Refs are an escape hatch for things that can't be modeled with React's existing reactivity features. As a rule of thumb: only use them when interacting with the DOM or the runtime directly (ie stuff such as browser APIs). Don't use them to store callbacks (prefer `useCallback, but in some rare cases it's acceptable to store them in `useState`).
Also, the the counter and the input field example is useless and contrived. And I realise they tried to keep the code simple to illustrate usage, but the author managed to make the example homeopathic. They should come up with a better example (ie the one in the React documentation is pretty good at illustrating why refs are useful).