Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const rootElement = document.getElementById("root");
- const Message = props => <div>{ props.children }</div>
- class App extends React.Component {
- state = {
- cities: ["Montreal", "Toronto", "Vancouver"],
- index: undefined,
- }
- render() {
- const { cities, index } = this.state;
- return (
- <div>
- <Message>
- You will travel to: { cities[index] }
- </Message>
- <button onClick={
- (event) => {
- this.setState({
- index: Math.floor(Math.random()*cities.length)
- });
- }
- }>
- Pick a city
- </button>
- </div>
- );
- }
- }
- ReactDOM.render(<App />, rootElement);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement