Skip to content

Commit

Permalink
Update atom-with-toggle-and-storage.mdx (pmndrs#2442)
Browse files Browse the repository at this point in the history
Updating recipe example with Typescript error fixes
  • Loading branch information
NehalDamania authored Mar 7, 2024
1 parent 8307f84 commit e4c4faa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/recipes/atom-with-toggle-and-storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export function atomWithToggleAndStorage(
key: string,
initialValue?: boolean,
storage?: any,
): WritableAtom<boolean, boolean | undefined> {
): WritableAtom<boolean, [boolean?], void> {
const anAtom = atomWithStorage(key, initialValue, storage)
const derivedAtom = atom(
(get) => get(anAtom),
(get, set, nextValue?: boolean) => {
const update = nextValue ?? !get(anAtom)
set(anAtom, update)
void set(anAtom, update)
},
)

return derivedAtom
return derivedAtom as WritableAtom<boolean, [boolean?], void>
}
```

Expand Down

0 comments on commit e4c4faa

Please # to comment.