Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
How to handle group radio button in React JS - FUNCTIONAL COMPONENT

I want to select only one option in the group of radio buttons. i can only find class component code online. Also help me with a onChange function to handle this.

const [radioOption, setradioOption]= useState(true)

const handleRadioChange = () =>{

}
    return(
<>
<Form.Group 
    inline 
    style={{
        display:'flex',  
        justifyContent:'space-between'}}
    >
    <Form.Radio
    onChange={handleRadioChange}
    value="All devices"
    label='All devices' 
    defaultChecked/>

    <Form.Radio
    onChange={handleRadioChange}
    value='Mobile only'
    label='Mobile only'/>

    <Form.Radio
    onChange={handleRadioChange}
    value='Desktop only'
    label='Desktop only'/>

</Form.Group>


</>)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To select only one option in the group of radio buttons you need to use same name in every input of radio. To save your choice we can use useState. Here is the complete example:

import React, { useState } from "react";

function Demo() {
  const [gender, setGender] = useState("Male");

  function onChangeValue(event) {
    setGender(event.target.value);
    console.log(event.target.value);
  }

  return (
    <div onChange={onChangeValue}>
      <input type="radio" value="Male" name="gender" checked={gender === "Male"} /> Male
      <input type="radio" value="Female" name="gender" checked={gender === "Female"}/> Female
      <input type="radio" value="Other" name="gender" checked={gender === "Other"} /> Other
    </div>
  );
}

export default Demo;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda