UNPKG

551 BJavaScriptView Raw
1import { useEffect, useRef } from 'react';
2/**
3 * Creates a `Ref` whose value is updated in an effect, ensuring the most recent
4 * value is the one rendered with. Generally only required for Concurrent mode usage
5 * where previous work in `render()` may be discarded before being used.
6 *
7 * This is safe to access in an event handler.
8 *
9 * @param value The `Ref` value
10 */
11
12function useCommittedRef(value) {
13 var ref = useRef(value);
14 useEffect(function () {
15 ref.current = value;
16 }, [value]);
17 return ref;
18}
19
20export default useCommittedRef;
\No newline at end of file