diff --git a/README.md b/README.md index bd1aad9..a4bcb73 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ npm i jotai-history ### Signature ```ts -function withHistory(targetAtom: Atom, limit: number): Atom +declare function withHistory(targetAtom: Atom, limit: number): Atom ``` This function creates an atom that keeps a history of states for a given `targetAtom`. The `limit` parameter determines the maximum number of history states to keep. @@ -30,7 +30,7 @@ import { withHistory } from 'jotai-history' const countAtom = atom(0) const countWithPrevious = withHistory(countAtom, 2) -export function CountComponent() { +function CountComponent() { const [count, previousCount] = useAtomValue(countWithPrevious) const setCount = useSetAtom(countAtom) @@ -55,7 +55,7 @@ type Undoable = { canUndo: boolean canRedo: boolean } -function withUndo(targetAtom: PrimitiveAtom, limit: number): Atom +declare function withUndo(targetAtom: PrimitiveAtom, limit: number): Atom ``` `withHistory` provides undo and redo capabilities for an atom. It keeps track of the value history of `targetAtom` and provides methods to move back and forth through that history. @@ -76,8 +76,13 @@ import { withUndo } from 'jotai-history' const counterAtom = atom(0) const undoCounterAtom = withUndo(counterAtom, 5) -export function CounterComponent() { - const { undo, redo, canUndo, canRedo } = useAtomValue(undoCounterAtom) +function CounterComponent() { + const { + undo, + redo, + canUndo, + canRedo, + } = useAtomValue(undoCounterAtom) const [value, setValue] = useAtom(counterAtom) return ( @@ -96,7 +101,7 @@ export function CounterComponent() { ``` ## Example -https://codesandbox.io/p/sandbox/musing-orla-g6qj3q?file=%2Fsrc%2FApp.tsx%3A10%2C23 +https://codesandbox.io/p/sandbox/musing-orla-g6qj3q ## Memory Management diff --git a/package.json b/package.json index 8169555..4450ba9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jotai-history", "description": "👻⌛", - "version": "0.2.0", + "version": "0.2.1", "author": "David Maskasky", "repository": { "type": "git",