我是新来的反应,并试图将编辑按钮放在编辑功能行旁边到数据库中但是我收到此错误消息。
错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。
Check the render method of `Department`.
▶ 23 stack frames were collapsed.
(anonymous function)
D:/React/employee-app/src/components/Department.js:22
19 | fetch('https://localhost:44363/api/department')
20 | .then(response=>response.json())
21 | .then(data=>{
> 22 | this.setState({deps:data});
| ^ 23 | }
24 | );
25 | }
View compiled
这是代码:
Department.js
export class Department extends Component{
constructor(props){
super(props);
this.state={deps:[],addModalShow:false,editModalShow:false}
}
componentDidMount(){
this.refreshList();
}
refreshList(){
fetch('https://localhost:44363/api/department')
.then(response=>response.json())
.then(data=>{
this.setState({deps:data});
}
);
}
componentDidUpdate(){
this.refreshList();
}
render(){
const {deps,depid,depname} = this.state;
let addModalClose = () => this.setState({addModalShow:false});
let editModalClose = () => this.setState({editModalShow:false});
return(
<div>
<Table className="mt-4" striped bordered hover size="sm">
<thead>
<tr>
<th>DepartmentId</th>
<th>DepartmentName</th>
<th>Option</th>
</tr>
</thead>
<tbody>
{deps.map(dep =>
<tr key = {dep.DepartmentID}>
<td>{dep.DepartmentID}</td>
<td>{dep.DepartmentName}</td>
<td>
<ButtonToolbar>
<Button
className="mr-2"
variant="info"
onClick={()=>
this.setState({editModalShow:true,depid:dep.DepartmentID,depname:dep.DepartmentName})
}>
)
}
}
Smart猫小萌
LEATH
相关分类