volleyball-dev-frontend/node_modules/@restart/hooks/esm/useCommittedRef.js
2025-06-02 16:42:16 +00:00

19 lines
546 B
JavaScript

import { useEffect, useRef } from 'react';
/**
* Creates a `Ref` whose value is updated in an effect, ensuring the most recent
* value is the one rendered with. Generally only required for Concurrent mode usage
* where previous work in `render()` may be discarded before being used.
*
* This is safe to access in an event handler.
*
* @param value The `Ref` value
*/
function useCommittedRef(value) {
const ref = useRef(value);
useEffect(() => {
ref.current = value;
}, [value]);
return ref;
}
export default useCommittedRef;