Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload not working #502

Closed
anshul-kai opened this issue Sep 26, 2016 · 3 comments
Closed

Hot reload not working #502

anshul-kai opened this issue Sep 26, 2016 · 3 comments

Comments

@anshul-kai
Copy link

Hi,

I apologize if this is an old request. I searched quite a bit but couldn't find a solution that works for my use case. I'm getting the following error when making changes via hot reloading.

<Provider> does not support changing store on the fly. It is most likely that you see this error because you updated to Redux 2.x and React Redux 2.x which no longer hot reload reducers automatically. See https://github.com/reactjs/react-redux/releases/tag/v2.0.0 for the migration instructions.

The documentation seems to be for a simple configureStore implementation and is very old too. I was unable to find any documentation around module.hot.acceptCallback but my code would fail with the following error until I explicitly assigned it a function value.

hot.acceptCallback is not a function

Code below. Any help is greatly appreciated.

const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const reducer = combineReducers(require('./redux/reducers/index'));
const store = createStoreWithMiddleware(reducer);

if (module.hot) {
  var acceptCallback = () => {
    const nextRootReducer = combineReducers(require('./redux/reducers/index'));
    store.replaceReducer(nextRootReducer);
  }

  // Enable Webpack hot module replacement for reducers
  module.hot.accept('./redux/reducers/index', acceptCallback);
  module.hot.acceptCallback = acceptCallback;
}
@timdorr
Copy link
Member

timdorr commented Sep 26, 2016

You are probably not putting your Provider right near your entry point and ReactDOM.render. It shouldn't be contained within a component, as something like React Hot Loader will attempt to recreate the store on a reload.

@timdorr timdorr closed this as completed Sep 26, 2016
@drewwells
Copy link

I'm seeing this issue. Is there a full example of an app to show how to avoid this behavior?

@anshul-kai
Copy link
Author

I had to struggle a bit but @timdorr is right about the Provider. I'm sharing my setup below with the hopes that it'll help.

index.ios.js

import React, { Component } from 'react';

import {
  AppRegistry,
} from 'react-native';

import Main from './src/Main';

class App extends Component {
  render() {
    return (
      <Main />
    );
  }
}

AppRegistry.registerComponent('App', () => App);

Main.js

import React, { Component } from 'react';
import { Provider } from 'react-redux';

import configureStore from './redux/configureStore';

import Navigation from './navigation/Navigation';

export const store = configureStore();

export default class Main extends Component {
  render() {
    return (
      <Provider store={store}>
        <Navigation />
      </Provider>
    );
  }
}

configureStore.js

import { createStore, combineReducers } from 'redux';

export default function configureStore() {
  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('./reducers/index', () => {
      const nextRootReducer = combineReducers(require('./reducers/index'));
      store.replaceReducer(nextRootReducer);
    });
  }

  const reducer = combineReducers(require('./reducers/index'));
  const store = createStore(reducer);
  return store;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants