-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Query component does not update #3126
Comments
I agree, the It would be great to provide a way to fetch the query again, either by re-render the component or with a children prop. |
The code I posted fixes the issue (assuming someone with more experience reviews it and agrees on the details).
...Based on what I've read this is how React is supposed to do it (render 2 times) and |
Thank you for the proposal, please open a PR so we'll be able to discuss about the code on it! |
Did you see my reply at the Merged link? I found an issue that will be considered a bug when someone else hits it. |
I have read it but not understood it. If there is a bug, please open a GitHub issue using the issue template, and allowing us to reproduce the bug. |
It isn't so much a bug as a pattern that needs to be included. Since querying is asynchronous it is possible that a component will be unmounted before control returns, creating a race that will cause an error. Check out the trashable react, a package that solves, and explains the core issue. I've used this in my implementation and it did the trick: |
Background:
The simple user story for background here is that I wanted to select a customer from a list and then display a list of locations associated with the customer to pick from. The first reference (customer) is sorted out by a
ReferenceInput
which then triggers aFormDataConsumer
which renders a custom component which uses aQuery
to look up the customer data and then pass the locations list of ids to a nestedQuery
to get the locations for use in a SelectInput. (Let me know if it would be helpful to see the code implementing the pattern above.)What you were expecting:
When changing customers I expected the locations
SelectInput
to be re-rendered with the new customer's locations as choicesWhat happened instead:
When setting a customer the first time it all worked fine. When changing the customer after that initial time all the machinery fired off but the data in the Query was from the initial customer.
Related code:
I fixed the issue by implementing
componentDidUpdate
. I copied the react-adminQuery
component and replacedcomponentDidMount
with all of the code here:Environment
^2.8.5
^16.8.6
The text was updated successfully, but these errors were encountered: