Skip to content

Preventing re-rendering when accessing view with argument #1742

Answered by jamonholmgren
NgoKnows asked this question in Q&A
Discussion options

You must be logged in to vote

I've replicated this @NgoKnows:

https://codesandbox.io/s/stupefied-brook-6h9df?file=/src/App.tsx

My initial thought is that it might make sense to use a types.map for this; essentially, you'd make something like this:

const AuthorBooks = types.model({
  id: types.identifier
  books: types.array(types.reference(Book))
})

// in BookStore
booksByAuthor: types.map(AuthorBooks)

Then populate that property when you update your books.

This is a little more manual than I'd like -- I wish your code worked out of the box -- but I don't think there's an easy way to do that. If anyone wants to take a stab at it, check out the sandbox and then share your findings here.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NgoKnows
Comment options

Answer selected by jamonholmgren
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants