Skip to content

Reducer Nested Object Update #4367

Closed Answered by markerikson
jd-carroll asked this question in Q&A
Discussion options

You must be logged in to vote

It looks like that state.parent = line is just filling in a default value, right?

Personally, I'd write it as:

if (!state.parent) {
  state.parent = {}
}

(Or if you really want to get fancy, the "nullish coalescing assignment operator": state.parent ??= {})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@EskiMojo14
Comment options

Answer selected by jd-carroll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants