I've been building a multi-step form flow in React/Gatsby, and right now i'm mapping over the form fields like so.
{clientContactDetailsData.map((item, idx) => (
<>
<Form.Label className="d-block text-left mb-0">{item.name}</Form.Label>
<Form.Control
type="text"
name={item.name}
className="selectButtons"
onChange={handleChange(item.value)}
defaultValue={values}
/>
</>
))}
name
and value
come from a JSON object that i'm exporting. name: 'Full Name'
, value: 'fullName'
For defaultValue
, I'm passing a values
variable through props. It's built as an object for all of the different fields:
const values = { clientType, clientGoal, clientDetails, contactPreference, fullName, companyName, email, phoneNumber };
The fields I'm using for clientContactDetailsData
are only fullName, companyName, email, phoneNumber
, so my goal is to map over only these, and pass them to the defaultValue
property, so that when I show a confirmation of the details, the values that the user entered will show. Full Name: John