🎯destination path

As we know, in Redux, the state is represented as a tree or a JSON object. At times, it becomes necessary to modify a nested object or a leaf in the tree. In order to achieve this, a destination path is provided, which points to the specific object that needs to be modified.

1. We will utilize the symbol > to indicate the specific object we intend to modify.

For example: we want to modify the name inside company inside the User. We have to write a path to go to that named object.

In this case, we use > symbol to point out

User>company>name 

In order to see how to use the Destination Path, we can examine an example of an insert function where we aim to insert an object into a leaf node of the tree.

Example of using Destination Path

I want to insert { gps: {x,y,z} } into User>address>geo

dispatch(insert('User>address>geo', gps', {x,y,z}); 

2. If you want to traverse an item in an array, you can use the symbol | [key]=[value] to specify the particular object that you want to modify.

Update companies with cid=5 in students with id=4 in MyClass

dispatch(update('MyClass>students|id=4>companies', { name: "Meta" }, 5, 'cid'))

Last updated