React_.createContext is not a function
See original GitHub issueHi so i have been trying to implement react context api into my project, After follow the steps in the guide: https://developerhandbook.com/react/build-a-complete-property-listings-page-with-react/
I ended up getting an error when i tried to display some of the information.
This is the error i got in my console log:
OrderListProvider.js:6 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_react__.createContext is not a function
at Object../src/context/OrderListProvider.js (OrderListProvider.js:6)
at __webpack_require__ (bootstrap 39db4eed0e38b5656c68:678)
at fn (bootstrap 39db4eed0e38b5656c68:88)
at Object../src/components/Home.js (FetchData.js:3)
at __webpack_require__ (bootstrap 39db4eed0e38b5656c68:678)
at fn (bootstrap 39db4eed0e38b5656c68:88)
at Object../src/App.js (fetch.js:461)
at __webpack_require__ (bootstrap 39db4eed0e38b5656c68:678)
at fn (bootstrap 39db4eed0e38b5656c68:88)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap 39db4eed0e38b5656c68:678)
at fn (bootstrap 39db4eed0e38b5656c68:88)
at Object.0 (registerServiceWorker.js:108)
at __webpack_require__ (bootstrap 39db4eed0e38b5656c68:678)
at bootstrap 39db4eed0e38b5656c68:724
at bootstrap 39db4eed0e38b5656c68:724
I tried updating my react since the guide mentioned i need 16.3 at least, and i only had 16.0.0.
However after updating react to the newest version it still says the same thing. I can’t seem to find any information about it in the release notes on github.
This is my createContext function:
const OrderListContext = React.createContext(DefaultState);
And this is where i consume it:
<OrderListProvider>
<OrderListConsumer>
{function (value) {
const { orderList } = value
return (
<ul>
{orderList.map(listing => (
<li>{listing.varetitle}</li>
))}
</ul>
)
}}
</OrderListConsumer>
</OrderListProvider>
This is my package.json
{
"name": "React_Demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"react": "^16.11.0",
"react-bootstrap": "^0.32.4",
"react-dom": ""^16.11.0"",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
"rimraf": "^3.0.0"
},
"scripts": {
"start": "rimraf ./build && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
I have recreated my code in stackblitz without data from a fetch funktion: https://stackblitz.com/edit/react-ssqc4t It doesn’t seem to show the error so i don’t understand why my code doesn’t work in visual studio 2017
I have also tried to verify and clear my npm cache, but it still shows the same error.
Node.js have also been updates to the newest version. Still the same error.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
You can remove your node_modules folder and re-install it again using
npm install
in your directory.Have you tried to re-download your node_modules? Having updated a single package might cause some inconsistency in the IDE you’re using.