我有 React JS 应用程序,它使用来自 ASP .NET Core Web API 的条目更新加速网格表。
我需要在插入后使用新条目更新网格。我在那里帮助和使用函数来做到这一点,但我得到了一个函数的无限循环。componentDidUpdate()
refreshList()
refreshList()
关于如何在没有该循环的情况下更新网格的任何想法?
import React, {Component} from 'react';
import {Table, Container} from 'react-bootstrap';
import {Button, ButtonToolbar} from 'react-bootstrap';
import {AddDepModal} from './AddDepModal';
import {EditDepModal} from './EditDepModal';
export class Department extends Component {
constructor(props){
super(props);
this.state = {deps:[], addModalShow: false, editModalShow: false}
}
componentDidMount()
{
this.refreshList();
}
refreshList()
{
fetch("https://localhost:5001/api/departments")
.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>Options</th>
</tr>
</thead>
江户川乱折腾
绝地无双
MMTTMM
相关分类