Edit: Answer Below
I've followed both of these tutorials on youtube (currently there aren't too many) but none of them work for me, it sends me this error from the Provider in the index.js:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
My code Context.js file:
import React from 'react'
export const Context = React.createContext();
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloProvider } from 'react-apollo';
import { Context } from './Context'
const client = new ApolloClient({
link: new HttpLink({ uri: process.env.API_URL }),
cache: new InMemoryCache()
})
ReactDOM.render(
<Context.Provider value={{text: 'ok'}}>
<BrowserRouter>
<ApolloProvider client={client}>
<App />
</ApolloProvider>
</BrowserRouter>
</Context.Provider>
, document.getElementById('root'));
registerServiceWorker();
I tried/checked:
Double checking I have 16.3.1 installed
putting context in or outside
<BrowserRouter>
Tried {Context} vs Context
reinstalling NPM packages
putting in { text: 'ok' } inside of createContext()
I tried 'create-react-context' and still got the same error, maybe this is a clue? I am not sure
tried [email protected] which works in tutorial
Some other stuff I have no forgot.
EDIT: Answer below
ReactDOM.render(...
– Sorrows<ApolloProvider client={client}>
Lets see the code for them. Where do you useContext.Consumer
? – Snorkel