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
There is no such thing as "action". Instead of them you can define class methods that modify data and corresponding components that use useChange or useValue listening that data are going to react accourdingly.
classFoo{publiccount=0;// this is the "action" itselfdoSomething(){// MyComponent listens to the property changesthis.count++;}}exportclassRootStore{foo=newFoo();constructor(){// call the "action" (the method) every 1 secondsetTinterval(()=>{this.foo.doSomething();},1000);}}exportdefaultnewRootStore();
You can also call the "action" at component with the help of useSilent hook if you don't want to export store object (exporting store itself is not prohibited but also is not recommended).
Plus to that you can get the store using React.useContext with use-change Context, then call the "action" by accessing it directly. It's recommended to use useSilent thought as a safer alternative to avoid direct store modifications within components.
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
-
There is no such thing as "action". Instead of them you can define class methods that modify data and corresponding components that use
useChange
oruseValue
listening that data are going to react accourdingly.You can also call the "action" at component with the help of
useSilent
hook if you don't want to export store object (exporting store itself is not prohibited but also is not recommended).Plus to that you can get the store using
React.useContext
with use-changeContext
, then call the "action" by accessing it directly. It's recommended to useuseSilent
thought as a safer alternative to avoid direct store modifications within components.Beta Was this translation helpful? Give feedback.
All reactions