From fe3b5c3ea28abed4b8b82457cf38e02324193b43 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 7 May 2019 08:10:57 +0200 Subject: [PATCH 1/5] fix: refactor for using useContext with TS --- src/ApolloConsumer.tsx | 2 +- src/ApolloContext.ts | 6 +++--- src/ApolloProvider.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ApolloConsumer.tsx b/src/ApolloConsumer.tsx index 5f5bf1cc27..b1b9fcea18 100644 --- a/src/ApolloConsumer.tsx +++ b/src/ApolloConsumer.tsx @@ -20,7 +20,7 @@ const ApolloConsumer: React.StatelessComponent = return props.children(context.client); } - return ApolloContext ? ( + return React.createContext ? ( {finish} diff --git a/src/ApolloContext.ts b/src/ApolloContext.ts index 6bf02b68d3..5ae3fd7d57 100644 --- a/src/ApolloContext.ts +++ b/src/ApolloContext.ts @@ -7,6 +7,6 @@ export interface ApolloContextValue { operations?: Map; } -export const ApolloContext = React.createContext - ? React.createContext(undefined) - : null; +type ContextType = ApolloContextValue | undefined; + +export const ApolloContext = React.createContext(undefined) diff --git a/src/ApolloProvider.tsx b/src/ApolloProvider.tsx index 91a9b50ccf..fbbcfcd0ce 100644 --- a/src/ApolloProvider.tsx +++ b/src/ApolloProvider.tsx @@ -50,7 +50,7 @@ export default class ApolloProvider extends Component {this.props.children} From 57207125a5a083bba9531d6f7dc35004e6ff1525 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 7 May 2019 08:20:56 +0200 Subject: [PATCH 2/5] fix: praect does not support .createContext --- src/ApolloConsumer.tsx | 2 +- src/ApolloContext.ts | 3 ++- src/ApolloProvider.tsx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ApolloConsumer.tsx b/src/ApolloConsumer.tsx index b1b9fcea18..5f5bf1cc27 100644 --- a/src/ApolloConsumer.tsx +++ b/src/ApolloConsumer.tsx @@ -20,7 +20,7 @@ const ApolloConsumer: React.StatelessComponent = return props.children(context.client); } - return React.createContext ? ( + return ApolloContext ? ( {finish} diff --git a/src/ApolloContext.ts b/src/ApolloContext.ts index 5ae3fd7d57..4d6583e7ab 100644 --- a/src/ApolloContext.ts +++ b/src/ApolloContext.ts @@ -9,4 +9,5 @@ export interface ApolloContextValue { type ContextType = ApolloContextValue | undefined; -export const ApolloContext = React.createContext(undefined) +export const ApolloContext = React.createContext && + React.createContext(undefined) diff --git a/src/ApolloProvider.tsx b/src/ApolloProvider.tsx index fbbcfcd0ce..5d3597889d 100644 --- a/src/ApolloProvider.tsx +++ b/src/ApolloProvider.tsx @@ -50,7 +50,7 @@ export default class ApolloProvider extends Component {this.props.children} From 3a7a92d7a73829c438dc28de7fb3645870cbba4d Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 7 May 2019 08:25:26 +0200 Subject: [PATCH 3/5] chore: resolve code inconsistency --- src/ApolloProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApolloProvider.tsx b/src/ApolloProvider.tsx index 5d3597889d..91a9b50ccf 100644 --- a/src/ApolloProvider.tsx +++ b/src/ApolloProvider.tsx @@ -50,7 +50,7 @@ export default class ApolloProvider extends Component {this.props.children} From 15f8d32d19a7dbf4dbc70c6c3039cdd7820acef4 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 7 May 2019 08:26:18 +0200 Subject: [PATCH 4/5] refactor: the added type can be removed --- src/ApolloContext.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ApolloContext.ts b/src/ApolloContext.ts index 4d6583e7ab..5a16a1706b 100644 --- a/src/ApolloContext.ts +++ b/src/ApolloContext.ts @@ -7,7 +7,5 @@ export interface ApolloContextValue { operations?: Map; } -type ContextType = ApolloContextValue | undefined; - export const ApolloContext = React.createContext && - React.createContext(undefined) + React.createContext(undefined) From 962a0b8b3ed7a1d5231794f68d63ffe5a35276c7 Mon Sep 17 00:00:00 2001 From: hwillson Date: Tue, 28 May 2019 12:59:49 -0400 Subject: [PATCH 5/5] Changelog update --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 04db8d4aa0..edf1389144 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,9 @@ - Make sure `MockedProvider` is using the proper CJS/ESM bundle, when referencing `ApolloProvider`.
[@jure](https://github.com/jure) in [#3029](https://github.com/apollographql/react-apollo/pull/3029). +- Adjust the `ApolloContext` definition to play a bit more nicely with + `React.createContext` types.
+ [@JoviDeCroock](https://github.com/JoviDeCroock) in [#3018](https://github.com/apollographql/react-apollo/pull/3018) ### Bug Fixes