2 回答

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊
如果我正確理解您的問題。您需要設(shè)置默認(rèn)狀態(tài)以避免空數(shù)據(jù)
如果在類的構(gòu)造函數(shù)中使用類組件,則應(yīng)設(shè)置狀態(tài)的默認(rèn)值
class SomeComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
someData: []
};
}
}
如果你使用功能組件,你應(yīng)該使用反應(yīng)鉤子
const SomeComponent = () => {
const [items, setItems] = useState([]); // default value empty array
};

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
根據(jù)以下條件打開您的模型 -
<DIV className="template-profile">
<Image
url={this.state.selectedImages.profilePicture}
mode={"Profile"}
/>
<h6>Hello I'm</h6>
<h1 className="template-profile-name">
Nabnit Jha
</h1>
<h6>
{this.state.AboutMeText} // here state value display successfully
</h6>
<DIV className="template-self-info">
{modelStatus&&<Modals modalBody={this.state.AboutMeText} modalHeading="About Me"></Modals>}
//here state value became null
</DIV>
</DIV>
實(shí)現(xiàn)它的功能
功能clickHandle
clickHandle=()=>{
this.setState({modelStatus:true})
}
您根據(jù)您的要求使用您的功能。
添加回答
舉報(bào)