-
hi, is it possible to dynamically create a MST model, for example based on the server response, which will contain the structure of this model? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
seems like this should be possible, but it may be somewhat difficult to use this in practice e.g. how do you actually work with the model after you have created it? do you know ahead of time what keys you expect? then if so, maybe you are better off creating MST models up front statically |
Beta Was this translation helpful? Give feedback.
-
I need to change the values of the fields in the model, the types of fields and their names I want to take in the schema from the request to the server
|
Beta Was this translation helpful? Give feedback.
-
I only know the format of the response for the schema, the name field can be any field name for the model. |
Beta Was this translation helpful? Give feedback.
-
Dynamic MST model creation is definitely possible with some boilerplate code. Quick and dirty basic example: |
Beta Was this translation helpful? Give feedback.
-
thanks for the idea, I decided to stick with a types.custom |
Beta Was this translation helpful? Give feedback.
Dynamic MST model creation is definitely possible with some boilerplate code.
However, this can be difficult to maintain and debug later on, especially if you want to use strong Typescript.
Quick and dirty basic example:
https://codesandbox.io/s/dynamic-mst-model-vyj4b?file=/src/index.js