Passing in runtime data on model instantiation #392
-
How do I pass runtime data when instantiating models?
Is there a better way to do this?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
What you're trying to do might not be sound. If you set Contexts might be what you're looking for. You can inject any kind of data into a state tree via a context and retrieve it at a child node, e.g. in your model instance. Just FYI, you don't need to decorate |
Beta Was this translation helpful? Give feedback.
What you're trying to do might not be sound. If you set
fooAction
upon model instantiation, then created a snapshot, and later restored the state from the snapshot again,fooAction
would not be set then because it's neither part of the snapshot (because (a) it's not a model prop and (b) functions aren't snapshotable/serializable anyway) nor part of the model definition.Contexts might be what you're looking for. You can inject any kind of data into a state tree via a context and retrieve it at a child node, e.g. in your model instance.
Just FYI, you don't need to decorate
setFooAction
with@modelAction
because it doesn't assign a value to a model prop.