( definition: AnyAtom | AtomConfig<any, any>, selectorOrInput?: any, compare = defaultCompare )
| 236 | compare?: (a: S, b: S) => boolean |
| 237 | ): S; |
| 238 | export function useAtom( |
| 239 | definition: AnyAtom | AtomConfig<any, any>, |
| 240 | selectorOrInput?: any, |
| 241 | compare = defaultCompare |
| 242 | ) { |
| 243 | const atomRef = useRef<any>(undefined); |
| 244 | |
| 245 | if (isAtom(definition)) { |
| 246 | return useSelector(definition, selectorOrInput ?? identity, compare); |
| 247 | } |
| 248 | |
| 249 | if (!atomRef.current) { |
| 250 | atomRef.current = definition.createAtom(selectorOrInput); |
| 251 | } |
| 252 | |
| 253 | const state = useSelector(atomRef.current, identity, compare); |
| 254 | |
| 255 | return state; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Creates or subscribes to an atom for the lifetime of a React component. |
searching dependent graphs…