Replies: 1 comment 10 replies
-
You should never import the store directly into components. Importing the store into a component ties that component to that exact store instance. This makes your code harder to test and the component impossible to reuse correctly. Also, if you end up importing the store just to dispatch actions, but do still use Always use the hooks to interact with the store, and wrap the app with There's no "stateful thing" involved with https://github.com/reduxjs/react-redux/blob/v7.2.4/src/hooks/useDispatch.js#L14-L17 return function useDispatch() {
const store = useStore()
return store.dispatch
} |
Beta Was this translation helpful? Give feedback.
-
Personally, I haven't experienced any problems if I simply use
store.dispatch()
inside my components.I even feel it's nicer than
useDispatch
in some cases, where multiple instances of the component are created, e.g. rows in a list or even table cells, because I feel the hook creates an extra "stateful thing" that each instance needs to keep track of individually.This question has actually been asked on stackoverflow a long time ago, but didn't draw much interest.
Beta Was this translation helpful? Give feedback.
All reactions