cssinjs / react-jss-hmr

Hot module replacement for react-jss
MIT License
7 stars 3 forks source link

Reduce lifecycle hooks and use of private methods #3

Open felthy opened 6 years ago

felthy commented 6 years ago

The componentDidUpdate() lifecycle method was only needed to work around a TypeError: Cannot read property 'detach' of undefined being thrown when a dynamic sheet is added via HMR.

This PR removes componentDidUpdate() and does all its work in componentWillReceiveProps() instead, so it won’t be able to be merged until react-jss stops attempting to detach the nonexistent previous dynamic sheet.

I also removed the call to createState() and instead restore the state that was created in the constructor. One fewer private method being called and it fixes the actual problem more directly.

felthy commented 6 years ago

Relies on cssinjs/react-jss#281