Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. import { useRef } from 'react';
  2.  
  3. const initialValue = '___INITIAL_REF_VALUE___';
  4.  
  5. function useLazyRef(constructor) {
  6. const ref = useRef(initialValue);
  7. if (ref.current === initialValue) {
  8. ref.current = constructor();
  9. }
  10. return ref;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement