在React中,我试图使用redux-form
执行API更新调用。我可以在initialize
的帮助下在编辑表单中获取数据。它运作良好。除非用户刷新浏览器。在这种情况下,我无法获取initialize
中的数据,因为它在道具/状态中不可用。Reactjs:在页面刷新时获取/保留REDX格式数据
constructor(props){
super(props);
}
componentWillMount(){
this.props.fetchUser(this.props.params.id);
}
render() {
const InitlValues = {
initialValues: {
"name": this.props.user.name,
"city": this.props.user.city
}
}
const { handleSubmit } = this.props;
return(
<form goes here..>
);
我也尝试作出反应的生命周期方法componentWillMount
用于读取数据,但它似乎并没有工作。
当用户刷新浏览器,它会引发错误:
遗漏的类型错误:空
我应该如何解决读取/当用户刷新页面保存的数据无法读取属性“名称”?
你好,谢谢你的建议。我确实尝试了'defaultProps',但它仍然会抛出相同的错误。 –