-
Hello! import shallow from 'zustand/shallow'
const getState = state => ({test:state.test, setTest: state.setTest})
export default function Home() {
const {test, setTest} = usePlayerStore(getState) // usePlayerStore(getState, shallow) -> both work the same way
return (
<h1 onClick={() => {setTest()}}>{test.value}</h1>
)
} store: const store = (set, get) => ({
test: {value: 0},
setTest: () => {
const n = {...get().test}
n.value = n.value +10;
set({test: n})
}
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Try creating another property like |
Beta Was this translation helpful? Give feedback.
-
Oh! I see |
Beta Was this translation helpful? Give feedback.
Try creating another property like
test2
andsetTest2
, and callingsetTest2
will let Home component re-render, even though it doesn't depend ontest2
.If you had a codesandbox of your example, I could modify it to show the difference.