graphql-hooks icon indicating copy to clipboard operation
graphql-hooks copied to clipboard

Argument of type 'Context<GraphQLClient | null>' is not assignable to parameter of type '

Open Jeric-Disney opened this issue 2 years ago • 3 comments

Package

graphql-hooks

Environment

  • graphql-hooks version: 5.11.4
  • react version: 18.2
  • Browser: chrome

Description

using useContext to get the client

How to reproduce

import {ClientContext} from 'graphql-hooks'
...
const client = React.useContext(ClientContext)

Jeric-Disney avatar Aug 13 '22 13:08 Jeric-Disney

Can you clarify what issue you're having? The types are defined here and they look correct to me.

simoneb avatar Aug 19 '22 16:08 simoneb

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 avatar Sep 30 '22 14:09 helderdb

@helderdb thanks for clarifying. Would you be interested in sending a PR to address this?

simoneb avatar Sep 30 '22 14:09 simoneb

@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.

helderdb avatar Oct 06 '22 10:10 helderdb

Thanks for the follow-up @helderdb . Feel free to close this issue then

simoneb avatar Oct 06 '22 10:10 simoneb