0
is the following I’m having a hard time finding where is the error of this code, I want to make a counter, but every time is saying that setCounter is not a function.
import React, {useState}from 'react';
//componente: e um bloco isolado de HTML, CSS e JS, o qual não interfere no resto da aplicação
// propriedade: informaçoes que um componete PAI passa para um componente filho.
// Estado:
//pro exemplo o app e um componente
function App() {
//bom aqui foi criado uma variavel counter que vai pegar o useState que vai comecar com o valor 0.
const {counter, setCounter} = useState(0);
function incrementCounter(){
setCounter(counter + 1);
}
return(
<>
<h1>Contador: {counter}</h1>
<button onClick={incrementCounter}>incrementar</button>
</>
)
}
export default App;
help me Please!
If this answer solved your problem and there is no doubt left, mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.
– Augusto Vasques