e679f45615
* - 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>
18 lines
488 B
TypeScript
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));
|
|
}
|