控制台上显示我的ReactJs应用程序出现“ no-undef”问题:
这是我编写的代码:
组件(..components / Equipment.js):
import React, { Component } from 'react';
import {connect} from 'react-redux';
class Equipment extends Component {
render() {
return (
<div>
{this.props.equipment.map(note => (
<div className="card">
<div className="card-header">
Equipment
</div>
<div className="card-content">
<table>
<tbody>
<tr>
<td>{equipment.identifier}</td>
</tr>
<tr>
<td>{equipment.location}</td>
</tr>
</tbody>
</table>
<button>edit</button><button>delete</button>
</div>
</div>
))}
</div>
)
}
}
const mapStateToProps = state => {
return {
equipment: state.equipment,
}
}
const mapDispatchToProps = dispatch => {
return {
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Equipment);
Reducer(..reducers / equipment.js):
const initialState = [
{
equipment: [
identifier: "My Machine 1",
location: "My Location 1"
]
}
];
export default function equipment(state=initialState, action) {
switch (action.type) {
default:
return state;
}
}
关于错误到底在哪里的任何想法? 谢谢。
答案 0 :(得分:1)
修复您的初始状态,应该是对象而不是数组:
const initialState = {
equipment: [{
identifier: "My Machine 1",
location: "My Location 1"
}]
}
也可以将equipment
更改为note
:
<tr>
<td>{note.identifier}</td>
</tr>
<tr>
<td>{note.location}</td>
</tr>
答案 1 :(得分:0)
在Equipment.js中用equipment
替换note
<tr>
<td>{note.identifier}</td>
</tr>
<tr>
<td>{note.location}</td>
</tr>