Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created April 22, 2024 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulieScanlon/6ebd7b22306216ad00a3254403230a04 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/6ebd7b22306216ad00a3254403230a04 to your computer and use it in GitHub Desktop.
Example of read write component
// 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