Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {fromNullable, none, Option} from 'fp-ts/lib/Option';
- import {RefObject} from 'react';
- type OptionRefObject<T> = RefObject<T> & {optionCurrent: Option<T>};
- const createOptionRef = <T extends HTMLElement>(): OptionRefObject<T> => {
- const value: OptionRefObject<T> & {
- _current: OptionRefObject<T>['current'];
- } = {
- _current: null,
- current: null,
- optionCurrent: none,
- };
- Object.defineProperty(value, 'current', {
- get: () => value._current,
- set: (refValue: OptionRefObject<T>['current']) => {
- value._current = refValue;
- value.optionCurrent = fromNullable(refValue);
- },
- });
- return value;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement