gaearon / gaearon/react-proxy

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

Open
#38 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
453
Forks
43
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.