目前我的元素仅在硬重置时呈现,我认为这是因为加载时我的状态设置为 Null,IDK 如何制作它以便存储我的 div 最简单/最好的方法是什么?
constructor(props) {
super(props);
this.state = {
healthData: null
}
}
componentDidMount() {
this.state.healthData = JSON.parse(localStorage.getItem('user_data'))
}
render() {
//gets users data and renders it to <p> items
const healthData = this.state.healthData;
console.log(healthData);
return healthData == null ? "" : (
<div className='main_Main'>
<div className='meal_divs'>
<p className='food_heading'>Status:</p>
<p className='food_text'>Your age is: {this.state.healthData.age}</p>
<p className='food_text'>Your gender is: {healthData.gender}</p>
<p className='food_text'>Your goal is: {healthData.goal}</p>
<p className='food_text'>Your height is: {healthData.height}</p>
<p className='food_text'>your weight is: {healthData.weight}</p>
</div>
请帮忙
摇曳的蔷薇
慕桂英546537
慕码人2483693
相关分类