亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錯誤:元素類型無效:編輯按鈕顯示錯誤

錯誤:元素類型無效:編輯按鈕顯示錯誤

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

2 回答

?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

export從兩個組件的第一行刪除關鍵字。僅在文件底部使用默認導出。


class Department extends Component{

 ....

 render() {

 }


}


export default Department;

然后對于進口使用這種類型import EditDepModal from './EditDepModal';


您可以閱讀更多關于 JS 中默認導入和命名導入之間的區別。


https://medium.com/@tharakabimal/understand-the-difference-between-default-and-named-imports-and-exports-fc04b2736c1a


查看完整回答
反對 回復 2022-10-21
?
LEATH

TA貢獻1936條經驗 獲得超7個贊

不確定您的項目設置是否有嚴格的 eslint 規則,并且您的更改是否由于缺少而被提交;at 語句:this.state={deps:[],addModalShow:false,editModalShow:false}



查看完整回答
反對 回復 2022-10-21
  • 2 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號