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