I want to implement a form that can handle array data with dynamic field. I build that app with TypeScript.
But it gave me an error:
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ name: string; email: string; }'.ts(7053)
I've searched google about that. I found a source that similar of my problem.
This is the part of code
const [formValues, setFormValues] = React.useState([{ name: "", email: "" }]);
let handleChangeForm = (i: any, e: any) => {
let newFormValues = [...formValues];
newFormValues[i][e.target.name] = e.target.value;
setFormValues(newFormValues);
};
This is a link of that source: https://bapunawarsaddam.medium.com/add-and-remove-form-fields-dynamically-using-react-and-react-hooks-3b033c3c0bf5
I change the code to solve a problem:
let handleChangeForm = (i: any, e: any) => {
setFormValues(([i][e.target.name] = e.target.value));
};