Context with store has been broken since 6.0.0
See original GitHub issueimport React, { Component } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { createStore } from 'redux';
import { connect, Provider } from 'react-redux';
const store = createStore(
(state) => state,
{ key: 'value' },
);
class App extends Component {
static contextTypes = {
store: PropTypes.object.isRequired,
};
constructor(props, context) {
super(props, context)
console.log(context)
}
render() {
return null
}
}
const CApp = connect()(App);
ReactDOM.render(
<Provider store={store}>
<CApp />
</Provider>,
document.getElementById('root')
);
I think this code is legal for any react
and redux
versions, but it is limited to react-redux
v5.x only. react-redux
>= v6.0.0 is not able to provide store
, it is always undefined.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Upgrading to React-Redux v6: Around the New Context API
Here is a short list of libraries that were initially broken by React-Redux v6, and have released (or in beta phase) their newest...
Read more >Breaking changes in EF Core 6.0 - Microsoft Learn
Complete list of breaking changes introduced in Entity Framework Core 6.0.
Read more >My create-react-app is failing to compile due to ESLint error
This issue has been fixed in the react-scipts:"4.0.3" but, the eslint errors present in the project are not converted to warnings by default....
Read more >Version Notes 6.0.0 - Apache Software Foundation
With each breaking changes release (like Struts 2.5), we had been only upgrading the MINOR part of the versioning schema. To fix that...
Read more >Resolve Pipelines — Autofac 6.0.0 documentation
You have access to the created instance after next returns. This is because calling next invokes the next middleware in the pipeline, which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@timdorr Sorry, you can’t understand what i am talking about.
The only one legal (and possible) way to receive
store
in v5.x wasstore
fromcontext
. This method has been clearly documented in v5.x.Today you are trying to say that first sentence about
Redux store available to any nested components
never existed,store
was not available in nested components and authors ofreact-redux
removed just internal functionality. It means that all packages and applications depends onreact-redux
v5.x and tries to accessstore
has been broken by design.Guys, if you are reading this issue, please try to avoid
react-redux
dependency in your applications. Authors of this package are not going to provide public api, they may always consider it as internal api and remove it without any notice (like deprecated).Oh, one other side note since I just re-read the original post here:
Yes, React-Redux v6 did drop the ability to pass
store
as a prop to connected components, but we brought that back in v7. That said, your original code snippet did not show that - you were mixing that up with passingstore
to<Provider>
, which has always been supported.You should really take the time to read my post The History and Implementation of React-Redux, which explains exactly why we’ve changed the implementation over time, and how.