LoginSignup
0

More than 3 years have passed since last update.

Recoil公式ドキュメント 翻訳㉟ APIリファレンス-Core-実用(Utils)-noWait()

Last updated at Posted at 2020-11-24

Recoilの公式ドキュメントをgoogle翻訳するとコードまで翻訳されてしまうのが面倒なのでQiitaにまとめてみます。

追々追加していきます。(多分)

公式ドキュメント

目次

全目次は一番下にあります


noWait(state)

指定されたatomまたはselectorの現在のstateのLoadableを返すselectorヘルパー。

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

​このヘルパーを使用すると、エラーが発生した場合や依存関係が保留中の場合に、スローすることなく非同期の可能性のある依存関係の現在のstateを取得できます。​useRecoilValueLoadable()と似ていますが、hookではなくselectorである点が異なります。​noWait()はselectorを返すので、今度はhookだけでなく他のRecoil selectorでも使用できます。

サンプルコード

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];
  }
})

参考サイト

公式ドキュメント
みらい翻訳


全目次

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0