教程 > recoil.js > 阅读:22

constselector(constant)——迹忆客-ag捕鱼王app官网

一个永远提供常量值的 selector

function constselector(constant: t): recoilvaluereadonly

如果你有一个使用有诸如 recoilvaluerecoilvaluereadonly 类型的接口,而这种类型可能会被不同的选择器实现所提供,那么 constselector 可能很有用。

这些选择器将基于引用值的平等进行记忆。所以constselector() 可以用相同的值多次调用,并且会提供相同的选择器。正因为如此,作为常量使用的值被限制在可以使用 recoil 序列化的类型上。对于这些限制的更多描述,请参阅 selectorfamily

示例

type myinterface = {
  queryforstuff: recoilvalue,
  ...
};
const myinterfaceinstance1: myinterface = {
  queryforstuff: selectorthatdoesquery,
};
const myinterfaceinstance2: myinterface = {
  queryforstuff: constselector(thing),
};

查看笔记

扫码一下
查看教程更方便
网站地图