question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onCompleted doesn't have the expected scope

See original GitHub issue

Hi, I’m using apollo/client": “3.6.8” The issue I have is when I’m trying to use a function inside onCompleted of useQuery I’m having the error: Uncaught ReferenceError: Cannot access 'myFunction' before initialization

For example:

const { data }: any = useQuery<MyQueryResult>(MyDocument, {
   onCompleted: (e) => myFunction()
})

const myFunction = () => ....

to solve it I need to move myFunction on top of useQuery, Is it new expected behavior or a bug?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
dylanwulfcommented, Oct 11, 2022

Not sure if this will fix the issue, but give v3.7 a try. PR #9801 made a small change to the time when onCompleted gets called, so there’s a chance it might help.

2reactions
DerJacquescommented, Oct 11, 2022

@jpvajda Can we re-open this issue, as the original problem has not yet been resolved? 😃

I’m seeing the same issue as @wuarmin: When I try to update state in my onCompleted callback, the state update is reverted on the next render. This only happens when the result comes from the cache: If it is fresh, it doesn’t happen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

proper use of onCompleted for GraphQL mutations
If the mutation is successful, the console should print console.log('Checking'); but that does not happen. The only output I get on the console ......
Read more >
Trouble understanding onCompleteScope in an Angular ...
In Angular, i have several methods in my component, it could be "closeEverything()", normally i call such function with "this.closeEverything()" ...
Read more >
Configuring a Step - Spring
playerSummarization begins processing and fails after 5 minutes. Run 2: playerLoad does not run, since it has already completed successfully, ...
Read more >
Promise.js-1 Source Code | Ext JS ... - modern
Ext.raise('Invalid parameter: expected an Array or Promise of an Array.'); ... onCompleted = Ext.Function.bind(onCompleted, scope);.
Read more >
Rebuilding Iraq: More Comprehensive National Strategy ...
On one hand, the strategy's purpose and scope is clear because it identifies ... Defeat the has no intention of it will make...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found