Newbie here.
I'll try my best to explain the issue.
Basically, I have this function that populates a form with existing data if the person filling out the form is the same as the user that logged in.
I'm trying now to reverse this function, so that if the user undoes this function, the form resets - i.e. as if it wasn't filled.
My issue is that I want to reset back to the initial state of name.
The way input field is formatted, having name : null or name : "" makes the form look like it's "filled". Just with no characters in the field itself.
How would I go about this?
const handleSameUser = useCallback(() => {
const newState = !sameUser
setSameUser(newState);
if (newState && user) {
handleUserDetails({
name: user?.name,
profilePic: user?.avatar,
});
} else {
handleUserDetails({ profilePic: null, name: ""});
}
}, [sameUser, setSameUser, user]);