From a9752f840a5c5129b425d79a2ed52c7f2d0aed62 Mon Sep 17 00:00:00 2001 From: David Maskasky Date: Thu, 5 Sep 2024 16:31:10 -0700 Subject: [PATCH] Update to version 0.2.1 --- README.md | 21 +++++++++++++-------- package.json | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bd1aad9..0b61162 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. @@ -23,14 +23,14 @@ The history atom tracks changes to the `targetAtom` and maintains a list of prev ### Usage -```tsx +```jsx import { atom, useAtomValue, useSetAtom } from 'jotai' 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. @@ -69,15 +69,20 @@ The returned object includes: ### Usage -```tsx +```jsx import { atom, useAtom, useAtomValue } from 'jotai' 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",