Skip to main content

isRecoilValue(value)

如果 value 是一个 atom 或者 selector 则返回 true,反之,返回 false

function isRecoilValue(value: mixed): boolean

示例#

import {atom, isRecoilValue} from 'recoil';
const counter = atom({  key: 'myCounter',  default: 0,});
const strCounter = selector({  key: 'myCounterStr',  get: ({get}) => String(get(counter)),});
isRecoilValue(counter); // trueisRecoilValue(strCounter); // true
isRecoilValue(5); // falseisRecoilValue({}); // false