Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert value as object on null #11

Open
Methuselah96 opened this issue Oct 16, 2020 · 3 comments
Open

Insert value as object on null #11

Methuselah96 opened this issue Oct 16, 2020 · 3 comments

Comments

@Methuselah96
Copy link
Owner


Migrated from don't!
Originally created by @piyaleemaiti on Fri, 08 May 2020 05:29:24 GMT


What happened

const original = { x: { y: null}}
setIn(original, ['x', 'y', 'z'], 456)

Here the old value was set to null, but I wanted to insert object value replace of null, how can I do that?

@Methuselah96
Copy link
Owner Author


Migrated from don't reference!
Original comment by @piyaleemaiti on Sat, 15 Aug 2020 14:08:51 GMT


Thanks @Methuselah96, I will try your suggestion.

@Methuselah96
Copy link
Owner Author


Migrated from don't reference!
Original comment by @bdurrer on Mon, 22 Jun 2020 11:15:02 GMT


Please use stackoverflow for questions. The issues on github are meant for bug/improvment reports.

PS: You likely forgot to assing the returned new collection:
notOriginalAnymore = setIn(original, ['x', 'y', 'z'], 456)

@Methuselah96
Copy link
Owner Author


Migrated from don't reference!
Original comment by @Methuselah96 on Fri, 14 Aug 2020 20:19:42 GMT


@piyaleemaiti I think the only way to do what you're asking is to provide the object value you want to replace null with like this:

const original = { x: { y: null}}
const result = setIn(original, ['x', 'y'], { z: 456 })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant