[Q] How to add extra container and modify creation #1979
Unanswered
ParadiseFallen
asked this question in
Q&A
Replies: 1 comment
-
Hi @ParadiseFallen! You could e.g. create your own import { getEnv, IStateTreeNode, types } from "mobx-state-tree";
type Env = {
baz: string;
};
const withEnv = (self: IStateTreeNode) => ({
views: {
get env() {
return getEnv<Env>(self);
}
}
});
const Model = types
.model({
foo: "bar"
})
.extend(withEnv)
.actions((self) => ({
afterCreate() {
console.log(self.env.baz);
}
}));
const model = Model.create({}, { baz: "qux" }); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I have a questuion about extending mst.
Im using kinda MVVM with react. so i need to pass dependencies to my models.
And i dont want to use env (has no strong type)
So im woundering how to create
.dependencies()
method for types.model builder and add types from dependencies to required params oncreate
methodBeta Was this translation helpful? Give feedback.
All reactions