onCompleted doesn't have the expected scope
See original GitHub issueHi, 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:
- Created a year ago
- Comments:16 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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.