我是新來的反應,并試圖將編輯按鈕放在編輯功能行旁邊到數據庫中但是我收到此錯誤消息。錯誤:元素類型無效:應為字符串(對于內置組件)或類/函數(對于復合組件),但得到:未定義。您可能忘記從定義組件的文件中導出組件,或者您可能混淆了默認導入和命名導入。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.jsexport 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}) }> )}}
錯誤:元素類型無效:編輯按鈕顯示錯誤
人到中年有點甜
2022-10-21 15:30:39