gpt4 book ai didi

reactjs - 使用react-redux时,_react.default.createContext不是一个函数

转载 作者:行者123 更新时间:2023-12-03 12:57:59 24 4
gpt4 key购买 nike

我在向入口点添加组件时遇到问题,这里立即弹出此错误,如何修复?我也尝试仅添加主组件,但无论如何我都会犯这个错误,在 main.jsx 中,只需使用渲染方法返回“hello world”类

_react.default.createContext is not a function

// App.jsx

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';

import 'react-select/dist/react-select.css';

import configureStore from './Data/store/configureStore';
import Main from "./Templates/Main/Main";

const store = configureStore();
render(
<div>
<Provider store={store}>
<BrowserRouter>
<Main/>
</BrowserRouter>
</Provider>
</div>,
document.getElementById('app-root')
);

Webpack 配置

'use strict';

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
devtool: 'eval-source-map',
entry: [
'webpack-hot-middleware/client?reload=true',
path.join(__dirname, 'src/app.jsx')
],
resolve: {
root: [
path.resolve(__dirname, "src"),
],
extensions: ['', '.js', '.jsx', '.css']
},
output: {
path: path.join(__dirname, '/public/'),
filename: '[name].js',
publicPath: '/'
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.tpl.html',
inject: 'body',
filename: 'index.html'
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}, {
test: /\.css$/,
loader: 'style!css'
}]
}
};

和依赖项

    "react": "^15.6.2",
"react-addons-update": "^15.6.2",
"react-bootstrap": "^1.0.0-beta.5",
"react-dom": "^15.6.2",
"react-helmet": "^5.2.0",
"react-redux": "^6.0.0",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-select": "^1.0.0-beta13",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"sequelize": "^3.20.0",
"sqlite3": "^4.0.6"

Google建议升级到ract版本16,但我不认为这是旧版本的问题。

最佳答案

react-redux v6.0.0 使用 React 提供的新上下文 api,为了使其工作,您需要将 react-redux 降级为v5.x.xreactreact-dom 升级到 v16.4 或上面

如果你使用的是yarn,你可以运行

yarn upgrade react react-dom

否则你可以使用 npm 运行

npm update react react-dom

您还可以在 package.json 中手动更改版本并运行 yarn installnpm install

关于reactjs - 使用react-redux时,_react.default.createContext不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54521723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com