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.

"Changing store on the fly" error when embedding <Provider> in a stateless component

See original GitHub issue

I’m working on a large app where we’re slowly integrating Redux piecemeal, essentially converting small components into “embedded Redux apps” that are the top-level of the Redux app, but not the top-level of the React app. This has worked for the most part, but we ran into this issue:

var ReduxRoot = props => (
    <Provider store={props}>
        <ReactReduxConnectedComponent/>
    </Provider>
)

It works fine, but any time the parent component re-renders, a <Provider> does not support changingstoreon the fly error pops up in the console.

This is fixed by adding a shouldComponentUpdate, and returning false if this.props and nextProps are equal. But that prevents us from taking advantage of the stateless component pipeline.

I know it’s not the idealized use of Redux to embed it within a React hierarchy instead of at the top level, so I’m not sure if this issue is considered worth addressing. But maybe it is.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

40reactions
totymedlicommented, Sep 1, 2017

Throwing in an answer for those who searched for the Error message in the title: Don’t call createStore in the provider attribute!

Don’t do this:

ReactDOM.render(
 <Provider store={createStore(reducers)}>
   <App/>
 </Provider>,
 document.getElementById('root')
);

The correct way is this:

var store = createStore(reducers);
ReactDOM.render(
 <Provider store={store}>
   <App/>
 </Provider>,
 document.getElementById('root')
);
26reactions
carslancommented, Jun 19, 2017

I had the same problem as given in the title but after the advise of @totymedli, i solved my problem. I am using react-native my approach for the solution was as advised;

const store = createStore(reducers);

export default class App extends React.Component {
  render() {
    return (
      
        <Provider store={store}>
          <View style={{ flex: 1 }}>
            <Header title="Tech Stack" />
            <LibraryList />
          </View>
        </Provider>
      
    );
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

react on rails - Redux store error: <Provider> does not support ...
Everything appears to work ok so far except my console shows error: <Provider> does not support changing `store` on the fly.
Read more >
Stateful and Stateless Applications and its Best Practices
Stateful vs Stateless Session. These both store state from client requests on the server itself and use that state to process further requests....
Read more >
The Guide to Learning React Hooks (Examples & Tutorials)
Learn all about React Hooks with this hands-on guide. Includes tutorials and code examples on using hooks for state and effects, for context...
Read more >
Adding interactivity to your Flutter app
You'll replace two stateless widgets—the solid red star and the numeric count next to ... emulator (part of the Android Studio install), you...
Read more >
Changing the Identity Store - Tableau Help
The backup is a best practice safeguard, in case you need to go back to your original Tableau Server configuration. Warning. Changing the...
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