I have an initial object called as initUser
, it consists of initial fields of the user as follows
const initUser: UserProfile = { firstName: '', lastName: '', phone: '', email: '', // and so on};
The object is very big, it has more than 30 fields in it. So while re initialising the state to its initial state, I did this
setUser(initUser);
Which didn't work.
But when I did this
setUser({...initUser});
It started to work, although the spread operator is very expensive as it makes the copy of the variable, so any idea why passing the variable is not working? Thank you in advance.
PS: The initUser
is placed in another file and is imported correctly since its working properly in the spread operator.