-
Notifications
You must be signed in to change notification settings - Fork 793
Query callback #208
Comments
@deoqc you can use componentWillRecieveProps(nextProps){
if (!nextProps.data.loading && this.props.data.loading) {
doMyCalBack();
}
} |
Yeah, I think I remember having in library in the past, but no problem using it in component. Thanks! |
(accidentally deleted my previous comment) I was wondering if there are any alternatives to firing a callback from For example:
Then in
You could argue that I can just pass This gets kinda messy because in some cases, I can comfortably execute If the answer is to simply pass props throughout the component's methods, then I'll take it. Thanks! |
Try pass
|
This is kind of annoying not being able to make a callback when query finishes fetching. componentWillReceiveProps(nextProps: Props) {
const { getProduct, setProductFiles } = nextProps
if (!nextProps.getProduct.loading && this.props.getProduct.loading) {
const images = []
getProduct.Product.images.forEach(i => {
let image = {...i}
image.preview = i.url
images.push(image)
})
setProductFiles(images)
}
} only works the first time the query is called, if you keep navigating around and comeback to the same route, the code inside the condition will not be called again, thus in my code, the images will not get refreshed and will show the last viewed item images. How can I get pass this? |
@johhansantana Have you found any workaround for that issue? |
Waiting for solution too. My problem is the same than @johhansantana with the latest packages. |
Hey @lirenyeo @Kisepro I think I fixed by using the fetch policy option in Apollo https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-fetchPolicy And using the option called network-only |
@johhansantana Yeah could be a nice workaround of a workaround :D The only problem could be the performance since it's not retrieved from the cache |
This work around is going away with React 17, seems more than ever we will need a callback provided by Apollo. |
Should this be reopened? |
This reminds me of the ancient years, where each improvement/advancement came after yeeeeeears. |
You can do something like this if you are making use of functional component |
Is there any way to call a callback after the query has finished loading?
The text was updated successfully, but these errors were encountered: