Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created April 22, 2024 21:03
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/204a7db97b3f4296b23d9bdf77194744 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/204a7db97b3f4296b23d9bdf77194744 to your computer and use it in GitHub Desktop.
Example of read and write component
// src/components/primitive-read-write-component.tsx
'use client';
import { useAtom } from 'jotai';
import { countAtom } from '../state';
export const ReadWriteComponent = () => {
const [count, setCount] = useAtom(countAtom);
const handleIncrement = () => {
setCount((value) => value + 1);
};
return (
<>
<div>{count}</div>
<button onClick={handleIncrement}>Increment</button>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment