Created
October 21, 2019 03:48
-
-
Save NimaBoscarino/658c6ead84a365b6961d6bfa47829ad0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
const HelloWorld = (props) => { | |
return ( | |
<h1>Hello {props.name}!</h1> | |
) | |
} | |
// display a number | |
// a button to increase the number | |
const Counter = () => { | |
// let number = 0 // remember this! | |
const [number, setNumber] = useState(0) | |
// Array destructuring | |
const increaseNumber = () => { | |
// number++ | |
// increase the number AND rerender the component | |
setNumber(number + 1) | |
// alert('Hello world!') | |
} | |
return ( | |
<div> | |
<h1>Count: {number}</h1> | |
<button onClick={increaseNumber}>Click!</button> | |
</div> | |
) | |
} | |
function App() { | |
return ( | |
<div> | |
<Counter /> | |
<Counter /> | |
<Counter /> | |
<Counter /> | |
<Counter /> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment