I can't figure out how to go one level deeper with the spread operator. I'm using Redux and I have this user state:
const INITIAL_STATE = {
token: null,
progress: {
hasSeenTutorial: false,
hasSignedUp: false
},
information: {
fullname: null,
username: null,
phone: null,
verificationCode: null
}
}
And I'm trying to change hasSeenTutorial
to true
using the spread operator in my action:
case 'UPDATE_TUTORIAL_SEEN':
return {...state, hasSeenTutorial: action.payload}
But this adds a new hasSeenTutorial
onto the end of my object, so obviously I want to use something like this:
case 'UPDATE_TUTORIAL_SEEN':
return {...state, progress.hasSeenTutorial: action.payload}
Note the added progress.
But this is not how you access it properly - it throws an error, what is the correct way?
NOTE: The key is to also not modify hasSignedUp - I want to only access and modify hasSeenTutorial using the spread operator.
EDIT: This question is unique - I'd like to know how to do it using only the spread syntax ...
and not using Object.create or Object.assign - if I used those I probably would not be mixing in ...
at the same time.