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

Connected components not working with react-hot-loader #116

Closed
edwjusti opened this issue Oct 3, 2018 · 5 comments
Closed

Connected components not working with react-hot-loader #116

edwjusti opened this issue Oct 3, 2018 · 5 comments
Labels

Comments

@edwjusti
Copy link

edwjusti commented Oct 3, 2018

Components wrapped with connect are not updated after a hot reload, only components without the connect wrapper get their hot updates.

@developit
Copy link
Owner

Is this with React, or Preact?

@edwjusti
Copy link
Author

edwjusti commented Oct 9, 2018

React

@developit
Copy link
Owner

This is likely fixed by 1028258.

@developit
Copy link
Owner

developit commented Jan 4, 2019

Released as 3.2.0. Please re-open this issue if its still there in 3.2.0.

@edwjusti
Copy link
Author

edwjusti commented Jun 4, 2019

I'm sorry for taking so long to answer, but this issue is still there with the latest release. However I was able to mitigate the issue by rewriting the connect function using classes, the following code receives updates properly:

export function connect(mapToProps, actions) {
  if (typeof mapToProps !== 'function') {
    mapToProps = select(mapToProps || []);
  }
  
  return Child => class Wrapper extends PureComponent {
    state = mapToProps(store.getState());

    update = state => this.setState(mapToProps(state));

    boundActions = actions ? mapActions(actions, store) : { store };

    componentWillMount() {
      store.subscribe(this.update);
    }

    componentWillUnmount() {
      store.unsubscribe(this.update);
    }

    render() {
      return createElement(
        Child,
        Object.assign(this.boundActions, this.props, this.state)
      );
    }
  };
}

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

No branches or pull requests

2 participants