You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import"./styles.css";import{create}from"zustand";import{useState}from"react";interfaceStoreA{count: number;incrementCount: ()=>void;}constuseStoreA=create<StoreA>((set)=>({count: 0,incrementCount: ()=>set((s)=>({count: s.count+1})),}));interfaceStoreB{getCount: ()=>number;}constuseStoreB=create<StoreB>((set)=>({getCount: ()=>{returnuseStoreA.getState().count;},}));exportdefaultfunctionApp(){constcount=useStoreB((state)=>state.getCount());constincrementCount=useStoreA((state)=>state.incrementCount);const[,setForceRender]=useState(0);return(<divclassName="App"><p>count: {count}</p><buttononClick={()=>incrementCount()}>Increment count</button><buttononClick={()=>setForceRender((n)=>n+1)}>
Force re-render (to see actual state change)
</button></div>);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
How can you read data from one store, and retain reactivity? By default it doesn't work:
Screen.Recording.2025-02-19.at.3.36.51.PM.mov
https://codesandbox.io/p/sandbox/hh7dxl?file=%2Fsrc%2FApp.tsx%3A3%2C34
Beta Was this translation helpful? Give feedback.
All reactions