2 回答

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

TA貢獻1795條經驗 獲得超7個贊
根據以下條件打開您的模型 -
<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>
實現它的功能
功能clickHandle
clickHandle=()=>{
this.setState({modelStatus:true})
}
您根據您的要求使用您的功能。
添加回答
舉報