Guest User

Untitled

a guest
Oct 21st, 2019
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const rootElement = document.getElementById("root");
  2.  
  3. const Message = props => <div>{ props.children }</div>
  4.  
  5. class App extends React.Component {
  6. state = {
  7. cities: ["Montreal", "Toronto", "Vancouver"],
  8. index: undefined,
  9. }
  10.  
  11. render() {
  12. const { cities, index } = this.state;
  13. return (
  14. <div>
  15. <Message>
  16. You will travel to: { cities[index] }
  17. </Message>
  18. <button onClick={
  19. (event) => {
  20. this.setState({
  21. index: Math.floor(Math.random()*cities.length)
  22. });
  23. }
  24. }>
  25. Pick a city
  26. </button>
  27. </div>
  28. );
  29. }
  30.  
  31. }
  32.  
  33. ReactDOM.render(<App />, rootElement);
RAW Paste Data