0
I’m taking a Reactjs course, and I’m trying to follow all the code examples, but my code is the same as the instructor’s and yet mine is not working the same as his. Every time you click increment, it is called a function to realize a basic account and uses useState to update the array value, but even so on my screen in the browser when clicking the button continues without updating and if I put a console.log() i can see that with each click on the button the value adds 1 more.
import React, {useState} from 'react'
import Header from './Header'
function App() {
const [count, setCounter] = useState(0)
function increment() {
setCounter(count + 1);
console.log(count)
}
return (
<div>
<Header>Contador: {count}</Header>
<button onClick={increment}>Incrementar</button>
</div>
)
}
export default App
You can show your
<Header>
? Your code works for me... https://jsfiddle.net/j81Le92q/– Sergio