JotaiJotai

状態
Primitive and flexible state management for React

freezeAtom

Usage

freezeAtom(anAtom): AtomType

freezeAtom takes an existing atom and returns a new derived "frozen" atom. The atom will be deeply frozen by Object.freeze. It is useful to find bugs where you unintentionally tried to change objects (states) which can lead to unexpected behavior. You may use freezeAtom with all atoms to prevent this situation.

Parameters

anAtom (required): An atom you wish to freeze.

Examples

import { atom } from 'jotai'
import { freezeAtom } from 'jotai/utils'
const objAtom = freezeAtom(atom({ count: 0 }))

CodeSandbox