Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 621 Bytes

freeze-atom.mdx

File metadata and controls

30 lines (21 loc) · 621 Bytes
title
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