Download react-use/src/useGetSet.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 632 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useGetSet.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useGetSet.ts
-
curl -L -o useGetSet.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useGetSet.ts
632 Bytes
| import { Dispatch, useMemo, useRef } from 'react'; | |
| import useUpdate from './useUpdate'; | |
| import { IHookStateInitAction, IHookStateSetAction, resolveHookState } from './misc/hookState'; | |
| export default function useGetSet<S>( | |
| initialState: IHookStateInitAction<S> | |
| ): [get: () => S, set: Dispatch<IHookStateSetAction<S>>] { | |
| const state = useRef(resolveHookState(initialState)); | |
| const update = useUpdate(); | |
| return useMemo( | |
| () => [ | |
| () => state.current as S, | |
| (newState: IHookStateSetAction<S>) => { | |
| state.current = resolveHookState(newState, state.current); | |
| update(); | |
| }, | |
| ], | |
| [] | |
| ); | |
| } | |