Skip to content

Instantly share code, notes, and snippets.

@gre
Created July 11, 2017 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gre/52e28f74eda0beccc17e880efe18c250 to your computer and use it in GitHub Desktop.
Save gre/52e28f74eda0beccc17e880efe18c250 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class Counter extends Component {
state = { count: 1 };
onClick = () => this.setState(({ count }) => ({ count: count + 1 }));
render() {
return (
<button onClick={this.onClick}>
{this.state.count}
</button>
);
}
}
class Demo extends Component {
componentDidMount() {
this.props.setVariables({ foo: 43 });
}
componentWillReceiveProps({ setVariables }) {
setVariables({ foo: 44 });
}
render() {
return (
<div>
<Counter />
</div>
);
}
}
class App extends Component {
state = { variables: { foo: 42 } };
setVariables = variables => this.setState({ variables });
render() {
return (
<div>
<Demo
setVariables={this.setVariables}
variables={this.state.variables}
/>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment