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

299
Vistas
How do I display any number of input text field on a modal depending on number of element in an array

Hello i'm new to ReactJS and Javascript. How do I display any number of textbox (input field, text input) on a modal, depending on the number of words that are in a sentence?

For example because there a 5 words in "Hope you are doing great", the number of input textfields in the modal should be 5.

I'm currently doing this:

  const [inputFields, setInputField] = useState([
    {word: ''},{word: ''},{word: ''},{word: ''},{word: ''}
])

and

<InputGroup className="mb-3">
            {inputFields.map((inputField, index) => (
              
                <Form key={index}>
                    <Form.Control label="word" name="word" value={inputField.word} />
  
                </Form>

            ))} 
           
        </InputGroup>

but its manual and i'd love to make it work dynamically on it's own.

I count the number of words as per usual:

 const handleShow = (poem) => {
  var lyric = poem.lyrics;
  var words_array = lyric.split(' ')
  var words_num = words_array.length
  console.log(words_num)
  setShow(true)
};

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0


export default function DynamicInputs({poem}){
   const [inputFields, setInputField] = useState([])


   useEffect(() => {
     setInputField(poem.lyrics.split(' ').map(word => ({word})))     
   }, [poem])

   return (
     <>
       {
        inputFields.map((field, index) => (
          <input type="text" key={index}/>
        )) 
       }
     </>
   )

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