Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.