From fd7714b883758b4771d58f541da7dc41130cca07 Mon Sep 17 00:00:00 2001 From: Ziad Beyens Date: Fri, 22 Dec 2023 19:08:43 +0100 Subject: [PATCH] Update README.md --- packages/jotai-x/README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/jotai-x/README.md b/packages/jotai-x/README.md index 5f0a691..01e0192 100644 --- a/packages/jotai-x/README.md +++ b/packages/jotai-x/README.md @@ -128,9 +128,7 @@ import { createAtomStore } from 'jotai-x'; export type AppStore = { name: string; - - // Functions: Jotai atoms do not support functions so we need to use an object here. - onUpdateName: { fn: (name: string) => void }; + onUpdateName: (name: string) => void; }; const initialState: Nullable = { @@ -153,7 +151,7 @@ const App = () => { return ( console.log(name) } + onUpdateName: (name: string) => console.log(name) }} // Either here or in initialValues name="John Doe" @@ -165,7 +163,7 @@ const App = () => { const Component = () => { const [name, setName] = useAppStore().use.name(); - const onUpdateName = useAppStore().get.onUpdateName().fn; + const onUpdateName = useAppStore().get.onUpdateName(); return (
@@ -185,7 +183,7 @@ const App = () => { console.log("Parent:", name) } + onUpdateName: (name: string) => console.log("Parent:", name) }} name="Parent User" > @@ -196,7 +194,7 @@ const App = () => { console.log("Child:", name) } + onUpdateName: (name: string) => console.log("Child:", name) }} name="Child User" > @@ -215,7 +213,7 @@ const Component = () => { // Here, we get the state from the parent scope const [name, setName] = useAppStore('parent').use.name(); // Here, we get the state from the closest scope (default) - const onUpdateName = useAppStore().get.onUpdateName().fn; + const onUpdateName = useAppStore().get.onUpdateName(); return (