types.reference not resolving the reference in mobx-state-tree

Viewed 1491

I am writing a search function that returns an array of ModelA or ModelB but when I use the references in my component, the reference is still a string. From the docs, I was expecting this to be the actual ModelA or ModelB so I feel like I am doing something wrong.

In my root store I create an array of references like this:

searchResults: types.array(
      types.union(
        types.late(() => types.reference(ModelA)),
        types.late(() => types.reference(ModelB)),
      ),
),

When I get them back from the request they are loaded into the store (I check by doing store.modelBs.get(<one of the ids>) but the component still gets the array of strings:

enter image description here

Does anyone know if this is valid/what I am doing wrong here?

1 Answers
Related