Skip to content

Commit

Permalink
feat(react): 4 new hooks!
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Jun 15, 2022
1 parent 3e1a664 commit 0802981
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
26 changes: 26 additions & 0 deletions src/react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,32 @@ export const useId = () => {
return useState(crypto.randomUUID())[0];
};

// useDebugValue
export const useDebugValue = (value: any) => {
console.log(value);
};

// useDeferredValue
export const useDeferredValue = (value: any) => {
return value;
};

export const useSyncExternalStore = (subscribe, getSnapshot) => {
const state = useState(getSnapshot());
useEffect(() => {
subscribe(state);
});
subscribe(state);
return state;
};

export const useImperativeHandle = (ref, create) => {
if (ref?.current) {
const object = create();
ref.current = { ...ref.current, ...object };
}
};

function different(value, i) {
return value !== this[i];
}
20 changes: 12 additions & 8 deletions src/react/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import {
hook,
useCallback,
useContext,
useDebugValue,
useDeferredValue,
useEffect,
useId,
useImperativeHandle,
useLayoutEffect,
useMemo,
useReducer,
useRef,
useState,
useSyncExternalStore,
useTransition,
} from './hooks';

Expand Down Expand Up @@ -200,20 +204,20 @@ export {
useId,
useCallback,
useContext,
// useDebugValue,
// useDeferredValue,
// useDeferredValue as unstable_useDeferredValue,
useDebugValue,
useDeferredValue,
useDeferredValue as unstable_useDeferredValue,
useEffect,
// useImperativeHandle,
// useInsertionEffect,
useImperativeHandle,
useEffect as useInsertionEffect,
useLayoutEffect,
useMemo,
// useMutableSource,
// useMutableSource as unstable_useMutableSource,
useSyncExternalStore as useMutableSource,
useSyncExternalStore as unstable_useMutableSource,
useReducer,
useRef,
useState,
// useSyncExternalStore,
useSyncExternalStore,
useTransition,
useTransition as unstable_useTransition,
jsx,
Expand Down

0 comments on commit 0802981

Please sign in to comment.