Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziad Beyens committed Dec 22, 2023
1 parent da92041 commit 29bcff9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppStore> = {
Expand All @@ -153,7 +151,7 @@ const App = () => {
return (
<AppProvider
initialValues={{
onUpdateName: { fn: (name: string) => console.log(name) }
onUpdateName: (name: string) => console.log(name)
}}
// Either here or in initialValues
name="John Doe"
Expand All @@ -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 (
<div>
Expand All @@ -185,7 +183,7 @@ const App = () => {
<AppProvider
scope="parent"
initialValues={{
onUpdateName: { fn: (name: string) => console.log("Parent:", name) }
onUpdateName: (name: string) => console.log("Parent:", name)
}}
name="Parent User"
>
Expand All @@ -196,7 +194,7 @@ const App = () => {
<AppProvider
scope="child"
initialValues={{
onUpdateName: { fn: (name: string) => console.log("Child:", name) }
onUpdateName: (name: string) => console.log("Child:", name)
}}
name="Child User"
>
Expand All @@ -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 (
<div>
Expand Down

0 comments on commit 29bcff9

Please sign in to comment.