gaearon / react-proxy

Proxies React components without unmounting or losing their state
460 stars 50 forks source link

Initialise state when getInitialState() is added after the initial render using HMR #38

Open insin opened 8 years ago

insin commented 8 years ago

When I'm working with hot reloading and adding state to a React.createClass component which didn't have it before, I usually have to hack in a one-time this.setState(this.getInitialState()) call somewhere to initialise the state and avoid TypeError: this.state is null in render().

Is it possible to detect that a getInitialState() has just been added to a component (or that state is null and getInitialState() exists, or some other heuristic) and have react-proxy do the setState(this.getInitialState()) bit for me, and is react-proxy the right place to do this?

vramana commented 8 years ago

I think this is related to #15

gaearon commented 8 years ago

Yeah it's probably the right place. Feel free to try to PR this :-)