Browse Source

useMutationEffect for updating a ref to latest value (#1363)

main
Dan Abramov 7 years ago
committed by GitHub
parent
commit
145debb391
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      content/docs/hooks-faq.md

4
content/docs/hooks-faq.md

@ -441,7 +441,7 @@ function Form() {
const [text, updateText] = useState('');
const textRef = useRef();
useEffect(() => {
useMutationEffect(() => {
textRef.current = text; // Write it to the ref
});
@ -482,7 +482,7 @@ function useEventCallback(fn, dependencies) {
throw new Error('Cannot call an event handler while rendering.');
});
useEffect(() => {
useMutationEffect(() => {
ref.current = fn;
}, [fn, ...dependencies]);

Loading…
Cancel
Save