Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/recipes/atom-with-compare.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export function atomWithCompare<Value>(
Here's how you'd use it to make an atom that ignores updates that are shallow-equal:

```ts
import { atomWithCompare } from 'XXX'
import { shallowEquals } from 'YYY'
import { atomWithCompare } from './atomWithCompare'
import { CSSProperties } from 'react'

const shallowEquals = (a: CSSProperties, b: CSSProperties) =>
Object.keys(a).every(
(key) => Object.is(a[key as keyof CSSProperties], b[key as keyof CSSProperties]),
) && Object.keys(b).every((key) => key in a)

const styleAtom = atomWithCompare<CSSProperties>(
{ backgroundColor: 'blue' },
shallowEquals,
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/atom-with-toggle-and-storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function atomWithToggleAndStorage(
And how it's used:

```js
import { atomWithToggleAndStorage } from 'XXX'
import { atomWithToggleAndStorage } from './atomWithToggleAndStorage'

// will have an initial value set to false & get stored in localStorage under the key "isActive"
const isActiveAtom = atomWithToggleAndStorage('isActive')
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/atom-with-toggle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The setter function can have an optional argument to force a particular state, s
Here is how it's used.

```js
import { atomWithToggle } from 'XXX'
import { atomWithToggle } from './atomWithToggle'

// will have an initial value set to true
const isActiveAtom = atomWithToggle(true)
Expand Down