Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested property assign in xstate?

I know that you can use the assign action creator like this:

const setFoo = assign({
  foo: (context, event) => "someValueBasedOnContextAndEvent",
});

But can you use it like this?

const setFoo = assign({
  foo: {
    bar: (context, event) => "someValueBasedOnContextAndEvent",
  }
});

Of course, without deleting all other nested values of foo.

like image 777
Paul Razvan Berg Avatar asked Feb 27 '26 02:02

Paul Razvan Berg


1 Answers

David Kourship (creator of xstate) answered this on Spectrum:

No you cannot, but you can make a custom assign function that does that.

So we basically have to create a custom reducer that selectively updates only one field in a nested object.

like image 179
Paul Razvan Berg Avatar answered Mar 04 '26 05:03

Paul Razvan Berg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!