-1
I made the following code, I would like to take the value of the "value" of the select, (the car color and show in the H3 tag when the button is triggered) I tried to use .target.value but without success
import React, { useState } from "react";
export default function Resultado() {
const [valor, setValor] = useState("Cor");
return (
<section>
<div>
<h3>Cor do Carro</h3>
<select>
<option value="Vermelho" selected>
Uno
</option>
<option value="Branca">Parati</option>
<option value="Azul">Fusca</option>
</select>
<button
onClick={(event) => {
setValor(event.target.value);
}}
>
Enviar Resultado
</button>
</div>
<h3>A cor do carro é: {valor}</h3>
</section>
);
}
This answer will help you. Basically what should be done is to move this
(event) => {setValor(event.target.value); }
to theselect
at the eventonChange
. Would be +- like this:<select onChange={(event) => {setValor(event.target.value);}>
– Cmte Cardeal