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

Cannot preserve state of dynamically generated classes #24

Closed
dallonf opened this issue Sep 12, 2015 · 1 comment
Closed

Cannot preserve state of dynamically generated classes #24

dallonf opened this issue Sep 12, 2015 · 1 comment

Comments

@dallonf
Copy link

dallonf commented Sep 12, 2015

I just discovered a bit of a gotcha with react-proxy (it might have been somewhere higher in the react-transform stack, this is my best guess as to where the issue belongs).

If you create a component class dynamically, like this contrived example derived from the react-transform-boilerplate project:

var WeirdCounter = (() => {
  var randomNumber = Math.round(Math.random() * 100);
  return class WeirdCounter extends Component {
    // .. irrelevant code copied from Counter elided
    render() {
      return (
        <h1 style={{ color: this.props.color }}>
          {randomNumber} is the best number! ({this.props.increment}): {this.state.counter}
        </h1>
      );
    }
  }
})();

It will render and reload just fine, but its state will be reset each time.

I would have just submitted a PR and added this to "Known Limitations", but I have no idea how to describe it in one concise bullet point. I certainly don't expect this to be a simple fix, or an issue that has any priority whatsoever ;) Just thought that this was an interesting gotcha and wanted to share that with the community.

@gaearon
Copy link
Owner

gaearon commented Sep 12, 2015

This is not a problem with react-proxy per se—the problem is uniquely identifying such “component class instances” across hot reloads. I created gaearon/babel-plugin-react-transform#18 to track this.

@gaearon gaearon closed this as completed Sep 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants