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
Since use-change is completely different thing we've ever used, I'm going to collect there tips, tricks, ideas and patterns that going to show how to solve common problems.
Access store from dev tools
There is the first one. Add the following snippet of code to access store while you at development env:
typeof window !== 'undefined' checks if it's a browser environment (useful for hybrid frameworks like NextJS).
window as unknown as { store: Store } allows to skip global definitions.
After that you can access store as a global variable called store.
How to make code nicer and avoid duplicating store selectors
Let's say you have a big component that uses a lot of properties implemented by use-change. At this case you need to pass store selector every time which makes code to look messy. There is a snippet from a real project that demonstrates the problem:
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
-
Since use-change is completely different thing we've ever used, I'm going to collect there tips, tricks, ideas and patterns that going to show how to solve common problems.
Access store from dev tools
There is the first one. Add the following snippet of code to access store while you at development env:
typeof window !== 'undefined'
checks if it's a browser environment (useful for hybrid frameworks like NextJS).window as unknown as { store: Store }
allows to skip global definitions.After that you can access store as a global variable called
store
.How to make code nicer and avoid duplicating store selectors
Let's say you have a big component that uses a lot of properties implemented by use-change. At this case you need to pass store selector every time which makes code to look messy. There is a snippet from a real project that demonstrates the problem:
As a solution define and export store selector constants and then replace store selectors by those constants.
At this case you still don't export/import modifiable store object and you get code look much readable.
Beta Was this translation helpful? Give feedback.
All reactions