Ask Your Question
4

Why is the component not getting re-rendered with Mobx State Tree?

asked 2023-03-24 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-09 11:00:00 +0000

ladyg gravatar image

There can be a few reasons why a component is not getting re-rendered with Mobx State Tree:

  1. The component is not using an observable value as a prop or state: Mobx State Tree only triggers a re-render if there is a change in an observable value that the component is using. If the component is not using an observable value as a prop or state, it will not re-render even if there is a change in the MST store.

  2. The component is not observing the needed data: If the component is observing the wrong part of the store, or if it's not observing the part of the store that is being updated, it will not re-render. Make sure that the component is observing the correct part of the store.

  3. The component is not using an observer or inject: In order for Mobx State Tree to trigger a re-render, the component needs to be wrapped in either the observer or inject higher-order component. Make sure that the component is properly wrapped.

  4. The component is not updating the store correctly: If the component is updating the store incorrectly, the store may not be triggering a re-render. Make sure that the component is correctly updating the store by using the built-in MST actions or by creating custom actions.

  5. The component is rendering too often: If the component is rendering too often, it may not appear to be re-rendering when it should. You can use the shouldComponentUpdate method to optimize the rendering of your component.

Overall, debugging why a component is not getting re-rendered with Mobx State Tree requires a careful examination of the code and a thorough understanding of how MST works.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-24 11:00:00 +0000

Seen: 13 times

Last updated: May 09 '21