Created
April 22, 2024 21:10
-
-
Save PaulieScanlon/6ebd7b22306216ad00a3254403230a04 to your computer and use it in GitHub Desktop.
Example of read write component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/components/object-read-write-component.tsx | |
'use client'; | |
import { useAtom } from 'jotai'; | |
import { objectAtom } from '../state'; | |
export const ObjectReadWriteComponent = () => { | |
const [obj, setObj] = useAtom(objectAtom); | |
const handleToggle = (event) => setObj((prev) => ({ ...prev, test: event.target.checked })); | |
return ( | |
<> | |
<pre>{JSON.stringify(obj, null, 2)}</pre> | |
<input onChange={handleToggle} type='checkbox' defaultChecked /> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment