我正在尝试使用两个基于类的组件<Cities>
和<Hospital>
另一个组件。
我收到一个错误:-
超过最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,就会发生这种情况。React 限制嵌套更新的数量以防止无限循环。
我正在尝试创建 4 个按钮,这些按钮将显示那些带有单击按钮的城市的医院。
import React,{ Component } from 'react';
import Hospital from './hospital/hospital'
import Cities from '../sidebarcomp/cities'
class Hospitals extends Component {
state = {
hospitals: [
{ id: 1, status: false, name: 'Apollo Hospital', city: 'Chennai', bedtype1: 500, bedtype2: 800, bedtype3: 1300,bed1av: 60, bed2av: 40, bed3av: 20, },
{ id: 2, status:false, name: 'Fortis Hospital', city: 'New Delhi', bedtype1: 600, bedtype2: 1000, bedtype3: 1400, bed1av: 60, bed2av: 40, bed3av: 20, },
{ id: 3, status: true, name: 'Tata Memorial Hospital', city: 'Mumbai', bedtype1: 400, bedtype2: 800, bedtype3: 1200, bed1av: 60, bed2av: 40, bed3av: 20, },
{ id: 4, status: true,name: 'Lilavati Hospital', city: 'Pune', bedtype1: 500, bedtype2: 900, bedtype3: 1300, bed1av: 60, bed2av: 40, bed3av: 20, }
],
};
render() {
return(
<React.Fragment>
<Cities
hospitals={this.state.hospitals}
/>
{this.state.hospitals.map((hospital, index) => {
if(hospital.status){
return (
<Hospital
name={hospital.name}
bed1av={hospital.bed1av}
bed2av={hospital.bed2av}
bed3av={hospital.bed3av}
key={hospital.id}
/>
)};
})}
</React.Fragment>
)
}
}
export default Hospitals;
UYOU
天涯尽头无女友
一只斗牛犬
相关分类