import React, { useState } from 'react'; const LCPFormRepeater = ({ fields, onSubmit }) => { const [formData, setFormData] = useState( fields.map(() => ({ value: '', // Initialize empty value for each field })) ); // Handle input field change const handleChange = (index, event) => { const updatedData = [...formData]; updatedData[index].value = event.target.value; setFormData(updatedData); }; // Handle form submission const handleSubmit = (event) => { event.preventDefault(); onSubmit(formData); // Call the passed in onSubmit callback with the form data }; return (
{fields.map((field, index) => (
{/* Render the corresponding input field based on the field type */} {field.type === 'text' && ( handleChange(index, e)} placeholder={field.placeholder} /> )} {field.type === 'number' && ( handleChange(index, e)} placeholder={field.placeholder} /> )} {field.type === 'email' && ( handleChange(index, e)} placeholder={field.placeholder} /> )} {field.type === 'textarea' && (