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

182
Visualizações
Changing label at the Formik switcher

I created switcher with Formik. The switcher label should change as well. It works for now, but only with boolean value.

enter image description here

However, I need not boolean at the label but string. For example, instead of "true/false" a need to show "Text1/Text2".

Here is my code:

 const createItemTypeInitState = {
              item_type: false, // this boolean values works properly, switching the label text between true/false
              item_type_name: "Text1", // here should be the string values "Text1"/"Text2", depending on the switcher on/off
    };

  const [initialValues, setInitialValues] = useState<createItemData>(
    createItemTypeInitState
  );
            
        <FormControl component="fieldset" variant="standard">
            <FormGroup>
                 <FormControlLabel
                    control={
                       <Android12Switch
                           checked={values.item_type}
                           onChange={handleChange}
                           name="item_type"
                        />
                     }
                     label={`${values.item_type}`}
                 />
            </FormGroup>
        </FormControl>

So I need to change boolean value item_type to the string value item_type_name. Please help me do it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have decided it by myself. It should be:

label={values.item_type ? "Text1" : "Text2"}
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