graphql-hooks
graphql-hooks copied to clipboard
Argument of type 'Context<GraphQLClient | null>' is not assignable to parameter of type '
Package
graphql-hooks
Environment
graphql-hooksversion: 5.11.4reactversion: 18.2- Browser: chrome
Description
using useContext to get the client
How to reproduce
import {ClientContext} from 'graphql-hooks'
...
const client = React.useContext(ClientContext)
Can you clarify what issue you're having? The types are defined here and they look correct to me.
I think I'm having the same issue. It started on version 5.1.0
The problem is that instead of wrapping the app with <ClientContext.Provider>...</ClientContext.Provider>, we're using
React.createElement(ClientContext.Provider,
{
value: client,
},
app);
This breaks the hooks plugin, and the context isn't defined anymore.
@helderdb thanks for clarifying. Would you be interested in sending a PR to address this?
@simoneb @Jeric-Disney Found the issue! We were instantiating the hooks plugin through a custom module. Since we were developing and referencing the module through a file resolver in our projects package.json, the module also had it's own node_modules folder. It then referenced that specific version of graphql-hooks in the module, while our project was using graphql-hooks from a level above in the node_modules folder.
So we were actually using separate instances, and that's why the ClientContext didn't work.
Thanks for the follow-up @helderdb . Feel free to close this issue then