Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda