-
Notifications
You must be signed in to change notification settings - Fork 786
Conversation
Well, I am stumped now. With old |
@FredyC I'll be pushing updates shortly that update |
@FredyC |
@hwillson Thanks. Looks like all is green, ready to merge :) |
Thanks for this @FredyC. Since this requires |
We don't necessarily want to expose the entire `ApolloContext`.
@hwillson That doesn't sound right...It should be in the master branch, that's why there was that check in case someone tries to use it without React 16.8. It would be a shame to have a new Context and unable to use it with Hooks. What if someone doesn't want to update to Apollo 3.0, but Besides, you already have React 16.8 in master, so I don't understand why such simple additive change could not be included there as well. It doesn't break anything until you actually use it. |
Thanks for the feedback @FredyC. Unfortunately, we don't want to introduce internal Hook use into For now people who want to use the new context API in |
the workaround for 2.x: You need to wrap the // MyApolloContext.js
const MyApolloContext = React.createContext()
export const MyApolloContextProvider = ({ children }) => (
<ApolloConsumer>
{client => <MyApolloContext.Provider value={client}>{children}</MyApolloContext.Provider>}
</ApolloConsumer>
)
export const useApolloClient = () => {
return useContext(MyApolloContext)
}
// app.js
<ApolloProvider client={client}>
<MyApolloContextProvider>
<MyComponent />
</MyApolloContextProvider>
<ApolloProvider>
// MyComponent.js
const MyComponent = () => {
const client = useApolloClient()
// ...
} |
@notgiorgi Your example doesn't work for me. First, I get an error as no default value is provided to React.createContext(), then I get an error when I attempt to use client.query() in MyComponent saying |
Checklist:
Quick fix for a leftover from context refactor so we can use it with hooks. I suppose tests are not needed for such a simple case?