Files
twenty/front/src/modules/ui/hooks/useRecoilScopedState.ts
T
Lucas Bordeau e679f45615 Feat/single entity select relation picker (#345)
* - Implemented recoil scoped state
- Implemented SingleEntitySelect
- Implemented keyboard shortcut up/down select

* Added useRecoilScopedValue

* Fix storybook

* Fix storybook

* Fix storybook

* Fix storybook

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-06-21 13:29:07 -07:00

18 lines
488 B
TypeScript

import { useContext } from 'react';
import { RecoilState, useRecoilState } from 'recoil';
import { RecoilScopeContext } from './RecoilScopeContext';
export function useRecoilScopedState<T>(
recoilState: (param: string) => RecoilState<T>,
) {
const recoilScopeId = useContext(RecoilScopeContext);
if (!recoilScopeId)
throw new Error(
`Using a scoped atom without a RecoilScope : ${recoilState('').key}`,
);
return useRecoilState<T>(recoilState(recoilScopeId));
}