Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useRef } from 'react';
- const initialValue = '___INITIAL_REF_VALUE___';
- function useLazyRef(constructor) {
- const ref = useRef(initialValue);
- if (ref.current === initialValue) {
- ref.current = constructor();
- }
- return ref;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement