Skip to content

How to achieve cross tree communication and data updates ? #2181

Discussion options

You must be logged in to vote

Hi @anishmiviewis - thanks for the question! Tree nodes cannot be shared across separate trees directly. Each node can only exist in exactly one tree.

However, if you want to just share that data across trees, you can always take a snapshot of the items you care about, and create copies in a separate tree. They will be distinct nodes from one another, so they won't share state, but this is an easy way to move data around from different trees. Here's an example using .map(getSnapshot) based on your CodeSandbox. I also fixed a bug where you updated a task item with an incorrect value (using the number 1 instead of the string "1"): https://codesandbox.io/p/sandbox/mobx-state-tree-playground-…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by anishmiviewis
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants