I have a multi-step form, which I am making using react, to work on validation I am using react-hook-form
.
I have already achieved 90% of things just one
You can create an array of 2 empty strings where first one represents first row F name,and second one represents first row S Name under yours inputHolder in the MainComponent:
const [inputHolder, setinputHolder] = useState([
{
id: 1,
fname: "",
sname: ""
}
]);
const [names, setNames] = useState(["", ""]);
Next,every time the user ads a new row you add to empty strings in names array.
const addRow = () => {
console.log(inputHolder.length);
let item = {
id: inputHolder.length + 1,
fname: "",
sname: ""
};
setinputHolder([...inputHolder, item]);
setNames([...names, "", ""]);
};
Where each empty string represents F name and S name. Finally,fields is set to names in second form:
fields: names,
component: (register, errors, defaultValues) => (