【发布时间】:2020-10-03 09:41:50
【问题描述】:
我正在使用 webpack 开发一个示例 react-redux 应用程序
webpack.config.js
var path=require('path');
const webpack = require('webpack');
module.exports= {
entry : './src/app.js',
output : {
filename : 'bundle.js',
path : path.resolve(__dirname,'public')
},
watch: true,
module : {
rules : [
{
test :/\.js$/,
exclude: /node_modules/,
loader : 'babel-loader',
query : {
"presets": ["@babel/preset-env","@babel/preset-react"]
}
}
]
}
}
bookList.js
"use strict"
import React from 'react';
import {connect} from 'react-redux';
import { bindActionCreators } from 'redux';
import {getBooks} from '../../actions/booksAction';
import {Grid, Col, Row, Button} from 'react-bootstrap';
import bookItem from './bookItem';
class BooksList extends React.Component
{
componentDidMount(){
this.props.getBooks()
}
render()
{
const booksList = this.props.books.map((booksArr)=> {
return (
<Col xs={12} sm={6} md={4} key={booksArr.id}>
testing
</Col>
)
})
return (
<Grid>
{booksList}
</Grid>
)
}
}
function mapStateToProps(state){
// which data to pass to react component
return{
books: state.books.books
}
}
function mapDispatchToProps(dispatch){
return bindActionCreators({getBooks:getBooks}, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(BooksList);
index.html(网格也将加载的主页)
<html>
<head>
<title>
Hello Redux
</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
<div id="root"></div>
</body>
<script src="bundle.js"></script>
</html>
错误 bundle.js:9 错误:缩小的 React 错误 #130;访问https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= 获取完整消息或使用非缩小开发环境获取完整错误和其他有用的警告。 (bundle.js:9)
我已经安装了引导程序,是否需要在 webconfig 中编写任何内容?谁能解决我的问题
我尝试在 webconfig.js 的预设中添加 'style-loader','css-loader' 但出现错误
【问题讨论】:
-
请提供为 booksList 编写的代码。如果没有书单,则它是未定义的,可能会导致此错误。尝试从渲染函数中删除书单并检查代码是否有效。
-
用 bookList 更新了代码
-
要找到真正导致错误的东西,尝试从返回块中删除 booksList 变量并检查错误是否消失。
-
我删除了 {booksList} 并将其设置为
它显示错误 -
如果我将
设置为 它正在工作。 Grid、Row、Col 标记不起作用
标签: javascript reactjs webpack react-redux jsx