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