This repository was archived by the owner on Apr 13, 2023. It is now read-only.
Description
Intended outcome:
I tried to use the exposed ApolloContext with React.useContext in my TS project.
Actual outcome:
I get a type error when using ApolloContext.
the problem is that the exposed ApolloContext type is defined as:
export interface ApolloContextValue {
client ?: ApolloClient < Object > ;
operations ?: Map < string , {
query : DocumentNode ;
variables : any ;
} > ;
}
export declare const ApolloContext : React . Context < ApolloContextValue | undefined > | null ;
where React.useContext doesn't accept null as a context.
How to reproduce the issue:
In a TS project:
import * as React from 'react' ;
import { ApolloContext } from 'react-apollo' ;
export function MyComponent ( props ) {
const apolloContext = React . useContext ( ApolloContext ) ;
return < div > stuff < / d i v > ;
}
I tried to use the codesandbox error template, but I got errors on all dependencies after changing the filenames to .tsx.
Version
Workaround
import * as React from 'react' ;
import { ApolloContext } from 'react-apollo' ;
import { ApolloContextValue } from 'react-apollo/ApolloContext' ;
type ApolloContextT = React . Context < ApolloContextValue > ;
export function MyComponent ( props ) {
const apolloContext = React . useContext ( ApolloContext as ApolloContextT ) ;
return < div > stuff < / d i v > ;
} Reactions are currently unavailable