教程 > recoil.js > 阅读:28

nowait(state)——迹忆客-ag捕鱼王app官网

一个 selector helper 方法,返回值为代表所提供的 atomselector 当前状态的 。

function nowait(state: recoilvalue): recoilvaluereadonly>

此 helper 方法可用于获取潜在异步依赖项的当前状态,在出现错误或依赖项仍然处于 pending 时不会抛出。它类似于 userecoilvalueloadable(),只不过它是一个 selector,而并非一个钩子函数。因为 nowait() 返回一个 selector,所以它可以被其他 recoil selectors 以及钩子所使用。

示例

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

查看笔记

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