Instantly share code, notes, and snippets.

@gre /main.js
Created Jul 11, 2017

Embed
What would you like to do?
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