redux-zero / redux-zero

A lightweight state container based on Redux

Home Page:https://matheusml1.gitbooks.io/redux-zero-docs/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React connect decorator prevents hot module reloading

jetako opened this issue · comments

The react/connect decorator prevents webpack and react-native hot module reloading. As far as I'm aware, React HMR doesn't work with pure functional components. This is an easy fix, simply change the innermost return value of connect() to a class instead of a function:

export default function connect(mapToProps, actions = {}) {
  return Child => (
    class ConnectWrapper extends React.Component<any> {
      render() {
        const { props } = this

        return (
          <Connect {...props} mapToProps={mapToProps} actions={actions}>
            {mappedProps => <Child {...mappedProps} {...props} />}
          </Connect>
        )
      }
    }
  )
}

I think this would go a long way towards adoption of redux-zero, which I absolutely love!

Thanks for this @jetako

Could you send this PR?

Sure @matheusml, I'll send over a PR shortly :)