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

117
Visualizações
Dynamically render a type specific input field on selecting an option from the dropdown list in reactjs

I am new to react and I have a dropdown list with some values, and I want to add a new input field upon selecting an option from the dropdown list. This is what I have so far,

import React, { useEffect } from 'react';

#creating an array of options
const options = [
    {
        name: 'First Name',
        id: 'text'
    }, 
    {
        name: 'Last Name',
        id: 'text'
    },
    {
        name: 'Phone',
        id: 'number'
    }
];

export const UserInputDefault = {
users: [], 
userId: []
}

#create component
const CreateNewUser = (data, setData) => {
    const setType = (type: string, index: number) => {
    if (index < 0 || index >= data.users.length) {
    return;
}
setData(update(data, {
    users: {
        [index]: {
            type: { $set: type }
        }
    }
}));
};

return (
      <div>
           <SelectList
                options={options}
                label="Input Type"
                action={(value: string) => {setType(value, index)}}
                selectedOption={data.questions[index].type}
            />
            <br/>
            #text input component 
            <TextInput
                variant="outlined"
                label="Display Text"
                value={data.questions[index].displayText}
                variables={[]}
                setValue={(value: any) => {setDisplayText(value, index)}}
                mode="html"
                error={Boolean(error?.displayText?.index === index && error?.displayText)}     
            />
      </div>
     );
}
export default CreateNewUser;

I am a little lost after this. I want the user to be able to select an option (First Name / Last Name / Phone) conditionally from the dropdown and a new input element should be inserted on selecting an option.

about 4 years ago · Juan Pablo Isaza
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