Skip to content

Latest commit

History

History
27 lines (21 loc) 路 693 Bytes

atom-with-reset.mdx

File metadata and controls

27 lines (21 loc) 路 693 Bytes
title
atomWithReset

Ref: #41

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

Creates an atom that could be reset to its initialValue with useResetAtom hook. It works exactly the same way as primitive atom would, but you are also able to set it to a special value RESET. See examples in Resettable atoms.

Example

import { atomWithReset } from 'jotai/utils'

const dollarsAtom = atomWithReset(0)
const todoListAtom = atomWithReset([
  { description: 'Add a todo', checked: false },
])