Home > front end >  Dynamic inputs in function
Dynamic inputs in function

Time:11-21

I need to do number of inputs that it dynamic's number , and for every input other name because I want to use in these inputs.

I call to the function in jsx with that

Array.apply(null, { length:  numberInputs}).map((e, i) => (
    <InputsNumber key={i} />
  ))

and I tried do for loop but because the function InputsNumber return tags of html it doesn't work well and the number is dynamic but all the number there same as my dynamic's number inputs

CodePudding user response:

Something like that ?

const dynamicInputs = (numberInputs) => {
    return Array.apply(null, { length: numberInputs }).map((e, i) => (
        <InputsNumber key={i} />
    ))
}

CodePudding user response:

Try this one

const dynamicFunc = (number) => {
    return Array.apply(null, {number}).map((num, index) => (
         <InputsNumber key={index} />
    ))
}
  • Related