I am trying to find a better way to handle all of my survey data at once. Able to have the components controlled is a good idea but I dont know if it is good practice to try to control them this way or I am just approaching this the wrong way.
This is the way I am trying to structure the survey.
const [survey, setSurvey] = useState({
questionOne: { question: '', a: '', b: '', c: '' },
questionTwo: { question: '', a: '', b: '', c: '' },
questionThree: { question: '', a: '', b: '', c: '' }
});
And this is the way that I am trying to handle the change:
const handleChange = (e, questionName) => {
const { name, value } = e.target;
console.log(questionName, name, value);
setSurvey({
...survey,
[questionName[name]]: value,
});
};
If any ideas if this can be targeted correctly I would very much appreciate any tips. Thank you.