-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React won't re-render after fetching array from server and storing in MobX state tree #1185
Comments
Possibly related to #1060? But I tried adding {JSON.stringify(this.props.order)} to my OrderListItem's render method, still not working.
|
Is flatlist observer too? |
I think the issue is that Flatlist only rerenders items when the reference to the data object changes. If it were observer it wouldn't be needed, but if it's out of your control you need to transform the data into a plain object (via getSnapshot) so it is a whole new object every time any of the orders change. @mweststrate would it make sense so getSnapshot is changed to only make the minimum mutations needed if a previous snapshot is fed into it? (so it keeps unchanged sub object references still). Or even better, so it's done automatically... Or that's already the case? |
@xaviergonz yes, snapshots already use structural sharing, so unchanged items are already recycled :) |
@mweststrate that's actually an awesome feature that I don't think is mentioned anywhere in the docs :) |
Nevermind, it is mentioned, just I never read it for some reason 😶 |
This issue has been automatically marked as stale because it has not had recent activity in the last 10 days. It will be closed in 4 days if no further activity occurs. Thank you for your contributions. |
For anyone else still facing issues with updating the flatlist , try this |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
Bug report
Sandbox link or minimal reproduction code
Parent.tsx
OrderList.tsx
OrderListItem.tsx
Describe the expected behavior
Parent.tsx is my screen, which renders a OrderList. When the screen first loads, I make an API call to fetch a list of Orders, which I then store in my MobX store. I would expect that the Parents screen re-renders and in turn render the OrderList since rootStore.orders.pending now has a length greater than 0.
Describe the observed behavior
Even after the API call is successful and the list of orders is stored in the MobX store, the OrderList component doesn't show up on the screen.
I've decorated the Parent Component, OrderList, and OrderListItem with @observer. Been stuck for hours trying to figure this out, please help.
The text was updated successfully, but these errors were encountered: