メインコンテンツにスキップ

noWait(state)

セレクターヘルパーで、提供された atom または selector の現在の状態の Loadable を返します。

function noWait<T>(state: RecoilValue<T>): RecoilValueReadOnly<Loadable<T>>

このヘルパーを使用して、可能性のある非同期依存関係の現在の状態を取得できますが、エラーが発生したり依存関係が保留されていたりしてもスローはされません。 useRecoilValueLoadable() と似ていますが、フックではなくセレクターです。 noWait() が返すのはセレクターなので、他の Recoil セレクターやフックでも使用することができます。

const myQuery = selector({
key: 'MyQuery',
get: ({get}) => {
const loadable = get(noWait(dbQuerySelector));

return {
hasValue: {data: loadable.contents},
hasError: {error: loadable.contents},
loading: {data: 'placeholder while loading'},
}[loadable.state];
}
})