Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!