Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Created October 21, 2019 03:48
Show Gist options
  • Save NimaBoscarino/658c6ead84a365b6961d6bfa47829ad0 to your computer and use it in GitHub Desktop.
Save NimaBoscarino/658c6ead84a365b6961d6bfa47829ad0 to your computer and use it in GitHub Desktop.
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