我无法在应用程序中使用react-bootstrap。每次我尝试从React Bootstrap导入和呈现组件时,都会发生此异常:
未捕获的永久违反:无效的挂接调用。挂钩只能在功能组件的主体内部调用。发生这种情况可能是由于以下原因之一
这就是我所做的:
npm install react-bootstrap bootstrap
安装了react-bootstrap和bootstrap import Button from 'react-bootstrap/Button';
中添加了Import-Statement <Button variant="primary">Primary</Button>
我在我的react应用程序中不使用钩子。 该网络应用程序可以正常运行,而无需做出反应引导!
为什么会引发此异常?如果有帮助,这是我的 package.json 文件:
{
"name": "sautercopyplanraum",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wbp": "webpack"
},
"keywords": [],
"author": "Tim Gerhard",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"aspnet-webpack": "^3.0.0",
"babel-loader": "^8.0.6",
"css-loader": "^3.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"style-loader": "^0.23.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5",
"webpack-dev-middleware": "^3.7.0",
"webpack-hot-middleware": "^2.25.0"
},
"dependencies": {
"@babel/runtime": "^7.4.5",
"bootstrap": "^4.3.1",
"core-js": "^3.1.4",
"moment": "^2.24.0",
"react-bootstrap": "^1.0.0-beta.9",
"react-contextmenu": "^2.11.0",
"react-hint": "^3.2.0",
"react-moment": "^0.9.2",
"react-router-dom": "^5.0.1",
"react-select": "^3.0.4",
"sweetalert2": "^8.13.0",
"sweetalert2-react-content": "^1.1.0"
}
}
这将是我的 webpack.config.js 文件:
const path = require('path');
module.exports = {
mode: 'development',
entry: { 'main': ['core-js/fn/promise', 'core-js/stable/object/assign', './wwwroot/src/app.js'] },
output: {
path: path.resolve(__dirname, 'wwwroot/dist'),
filename: 'bundle.js',
publicPath: 'dist/'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
resolve: {
extensions: [".js", ".jsx"]
},
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react', '@babel/preset-env', {
'plugins': ['@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-runtime']
}]
}
}
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
}
};