Closed simoneduca closed 6 years ago
I'll test this out on one component to see how much effort is required and then decide if it's worth it.
Tutorials are probably the most complicated example, because they use static methods. https://github.com/zooniverse/Panoptes-Front-End/blob/f632f0800122c8d7e606f6e2c9fd82b59ab4740a/app/classifier/index.cjsx#L66
Also, looking through that file, I see that I've missed adding the store argument in ComponentWillReceiveProps
.
Worth noting that the react-redux
docs recommend against using props except as a last resort.
If you really need to, you can manually pass store as a prop to every connect()ed component, but we only recommend to do this for stubbing store in unit tests, or in non-fully-React codebases. Normally, you should just use
<Provider>
. https://github.com/reactjs/react-redux/blob/master/docs/api.md#provider-store
PFE seems to fit the last resort scenario, no? Because the error message returned when store
is undefined says:
Uncaught Error: Could not find "store" in either the context or props of "Connect(TaskTranslations)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(TaskTranslations)".
It does not say use context
manually/explicitly.
Master, at the moment, explicitly passes the store as a prop but wrapping modal content in<Provider store={this.context.store} >
would also work. See the advice about dealing with context errors towards the bottom of the troubleshooting page: https://github.com/reactjs/react-redux/blob/master/docs/troubleshooting.md
In fact #4280 works because PassContext
is being used as a Provider in that PR.
Closing since the context API is now properly finalized, documented, and supported in React 16. Specific refactoring for the newer API should have separate issues opened for it if it needs to be done.
Expected behavior
Use
props.store
to access redux store, instead ofcontext.store
. The reason being thatcontext
is explicitly not recommended by React docs.Here's a list of all components which currently use
connect()
, and would need to be updated to receive the store as a prop./app/classifier/classifier.jsx
/app/classifier/index.cjsx
/app/classifier/translations.jsx
/app/classifier/feedback/feedback-summary-container.jsx
/app/classifier/feedback/svg-feedback-viewer.jsx
/app/classifier/feedback/svg-tooltip-layer.jsx
/app/classifier/tasks/translations.jsx
/app/pages/project/index.cjsx
/app/pages/project/project-translations.jsx
/app/pages/project/about/index.jsx