I am trying to achieve a dynamic form using react hooks and .map();
What I have achieved so far is to generate the form static like in this example : https://codesandbox.io/s/material-demo-ndh9q
this is my static form :
<form className={classes.root} noValidate autoComplete="off">
<Grid container spacing={4}>
<Grid item xs={12} sm={6} md={4}>
<TextField id="profile" label="Name" fullWidth={true} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<TextField id="profile" label="Email" fullWidth={true} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<TextField id="profile" label="Address" fullWidth={true} />
</Grid>
{/* textarea */}
<Grid item xs={12} sm={12} md={12}>
<TextField
label="Info"
multiline
rows={1}
rowsMax={4}
fullWidth={true}
/>
</Grid>
</Grid>
</form>
and here I am trying to make the form dynamic:
const initialState = { name: "", email: "", address: "", info: "" };
export default function BasicTextFields() {
const [inputs, setInputs] = useState({ ...initialState });
return(
<form className={classes.root} noValidate autoComplete="off">
<Grid container spacing={4}>
{inputs.map((item, index) => (
<Grid item xs={12} sm={6} md={4}>
<TextField id={index`${item}`} label={item} fullWidth={true} />
</Grid>
)}
</Grid>
</form>
)}
but it is returning error, not sure why, can someone help me also with a detailed info please. keep in mind that also last field of the form is a textarea so gets particular attribute.
ThankYou !
inputsis an object, right?