LoginSignup
0
1

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-11-24

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

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

公式ドキュメント

目次

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


constSelector(constant)

​常に一定の値を提供するselector.

function constSelector<T: Parameter>(constant: T): RecoilValueReadOnly<T>

constSelectorは、異なるselector実装によって提供されるRecoilValue<T>RecoilValueReadOnly<T>などのタイプを使用するインタフェースがある場合に便利です。

​これらのselectorは、参照値の等価性に基づいて記憶します。​したがって、constSelector()を同じ値で複数回呼び出すことができ、同じselectorが提供されます。​このため、定数として使用される値は、Recoil serializationを使用してシリアライズできる型に制限されます。​制限については、selectorFamilyのドキュメントを参照してください。

サンプルコード

type MyInterface = {
  queryForStuff: RecoilValue<Thing>,
  ...
};

const myInterfaceInstance1: MyInterface = {
  queryForStuff: selectorThatDoesQuery,
};

const myInterfaceInstance2: MyInterface = {
  queryForStuff: constSelector(thing),
};

参考サイト

公式ドキュメント
IT用語辞典 e-Words シリアライズ
みらい翻訳


全目次

0
1
0

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
1