Skip to content

Commit

Permalink
forgot to update README
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Apr 25, 2024
1 parent 2b2f3ea commit f8eea94
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ npm install zustand zustand-valtio valtio
```jsx
import { createWithProxy } from 'zustand-valtio';

const [useCounterState, counterState] = createWithProxy({ count: 0 });
const useCounterState = createWithProxy({
count: 0,
inc() {
this.count++;
},
});

const Counter = () => {
const count = useCounterState((state) => state.count);
const inc = () => ++counterState.count;
const inc = useCounterState((state) => state.inc);
// Or this works too
// const inc = () => ++useCounterState.proxyState.count;
return (
<div>
{count} <button onClick={inc}>+1</button>
</div>
<>
<div>Count: {count}</div>
<button type="button" onClick={inc}>
+1
</button>
</>
);
};
```
Expand Down

0 comments on commit f8eea94

Please sign in to comment.