Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import {fromNullable, none, Option} from 'fp-ts/lib/Option';
  2. import {RefObject} from 'react';
  3.  
  4. type OptionRefObject<T> = RefObject<T> & {optionCurrent: Option<T>};
  5.  
  6. const createOptionRef = <T extends HTMLElement>(): OptionRefObject<T> => {
  7. const value: OptionRefObject<T> & {
  8. _current: OptionRefObject<T>['current'];
  9. } = {
  10. _current: null,
  11. current: null,
  12. optionCurrent: none,
  13. };
  14.  
  15. Object.defineProperty(value, 'current', {
  16. get: () => value._current,
  17. set: (refValue: OptionRefObject<T>['current']) => {
  18. value._current = refValue;
  19. value.optionCurrent = fromNullable(refValue);
  20. },
  21. });
  22.  
  23. return value;
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement