Skip to content

Commit 145debb

Browse files
authored
useMutationEffect for updating a ref to latest value (reactjs#1363)
1 parent c30ab0e commit 145debb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

content/docs/hooks-faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function Form() {
441441
const [text, updateText] = useState('');
442442
const textRef = useRef();
443443
444-
useEffect(() => {
444+
useMutationEffect(() => {
445445
textRef.current = text; // Write it to the ref
446446
});
447447
@@ -482,7 +482,7 @@ function useEventCallback(fn, dependencies) {
482482
throw new Error('Cannot call an event handler while rendering.');
483483
});
484484
485-
useEffect(() => {
485+
useMutationEffect(() => {
486486
ref.current = fn;
487487
}, [fn, ...dependencies]);
488488

0 commit comments

Comments
 (0)