-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useSubscription "loading" and "data" out of sync when used with other hooks #7198
Comments
We finally found a work around for this issue. We don't use the returned values of the const [subscriptionState, setSubscriptionState] = React.useState({
data: undefined,
loading: true,
});
const prevSubscriptionVariables = usePrevious(subscriptionVariables);
useEffect(() => {
if (!equals(subscriptionVariables, prevSubscriptionVariables)) {
setSubscriptionState({
data: undefined,
loading: true,
});
}
},
[subscriptionVariable, prevSubscriptionVariable]);
useSubscription(CAPTURE_AGGREGATE_SUBSCRIPTION, {
onSubscriptionData: ({subscriptionData}) => {
setSubscriptionState({
data: subscriptionData.data,
loading: false,
});
},
variables: subscriptionVariables,
});
const previousSubscriptionState = usePrevious(subscriptionState)
useEffect(() => {
if(previousSubscriptionState.loading && !subscriptionState.loading){
console.log("Here is your new data after changing variable", subscriptionState.data)
}
}, [subscriptionState, previousSubscriptionState]); Hope this will help someone and that this will be fixed soon in the |
We are running into this same bug. As far as I can tell this problem is caused because the I think the right way to fix this would be for I tried making this change to Would love to get some feedback from someone more familiar with the |
@mzbyszynski do you have something new about this? |
@christophediprima Same issue here |
Hey 👋🏼 |
Hi,
the |
You have forgotten to write data , loading and error behind them , it should be like
|
We recently released a rewrite of Data is now synchronized using If you find any problems with |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I am using version 3.2.4 of @apollo/client and there is no way of using a useEffect to check when loading moves from true to false with new data when you have other hooks changing state.
You simply get
loading
back tofalse
and the old data as soon as you are using other hooks that changes the state of your component.The text was updated successfully, but these errors were encountered: