JotaiJotai

状態
Primitive and flexible state management for React

atomWithReset

引用: https://github.com/pmndrs/jotai/issues/41

function atomWithReset<Value>(
initialValue: Value
): WritableAtom<Value, SetStateAction<Value> | typeof RESET>;

创建一个可以使用 useResetAtom hook 重置为其 initialValue 的原子。 它的工作方式与原始原子完全相同,但您也可以将其设置为特殊值 RESET。 请参阅 可重置原子 中的示例。

示例

import { atomWithReset } from "jotai/utils";
const dollarsAtom = atomWithReset(0);
const todoListAtom = atomWithReset([
{ description: "Add a todo", checked: false },
]);