I'm learning React and starting with handling state in a CRUD form via the useState Hook. Something like this:
const [data, setData] = useState({});
where data is the object containing the state of the form and his props are the values of the inputs.
I have two concerns:
1) Unnecessary rendering. If when an input is changed (onChange or onBlur event) I update the state, via a typical handleChanged function, for example:
const handleChanged = (e) => {
setData(...data, [e.target.name]: e.target.value)
});
does the form render only the specific changed input or the entire form (all inputs) ? In case it was for all inputs, how could that be avoided?
2) Arrays and useState.
If instead of having a single data object I have an array of data objects, eg. in a editable table, how would the useState be handled for each array element? I have searched for examples but they are all for a single object.