question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context with store has been broken since 6.0.0

See original GitHub issue
import 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:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
andrew-aladevcommented, Oct 19, 2020

@timdorr Sorry, you can’t understand what i am talking about.

The only one legal (and possible) way to receive store in v5.x was store from context. This method has been clearly documented in v5.x.

The <Provider /> makes the Redux store available to any nested components that have been wrapped in the connect() function.

Note: If you really need to, you can manually pass store as a prop to a connected 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>.

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 of react-redux removed just internal functionality. It means that all packages and applications depends on react-redux v5.x and tries to access store 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).

0reactions
markeriksoncommented, Oct 20, 2020

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 passing store 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found