question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React_.createContext is not a function

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
vaporwaviecommented, Oct 28, 2019

You can remove your node_modules folder and re-install it again using npm install in your directory.

1reaction
vaporwaviecommented, Oct 28, 2019

Have you tried to re-download your node_modules? Having updated a single package might cause some inconsistency in the IDE you’re using.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"React.createContext is not a function" - but I am not using it
createContext is not a function " error while running a react-native application. I searched for 'createContent' in the code, it doesn't exist.
Read more >
[Bug]: TypeError: React.createContext is not a function · Issue ...
You are not using Headless UI in the linked repo, so can't really help you there. If this problem still occurs please open...
Read more >
Uncaught TypeError: _react.default.createContext is not a ...
createContext is not a function. I'm getting this error and the app won't render: Uncaught TypeError: _react.default.createContext is not a ...
Read more >
[Solved]-"React.createContext is not a function" - appsloveworld
In your package react and react-dom are not having the same version which is why you get the error. react-dom@16.4.0 will want to...
Read more >
createContext - React Docs
createContext returns a context object. The context object itself does not hold any information. It represents which context other components can read or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found