【发布时间】:2017-04-08 04:07:20
【问题描述】:
在 React 中,我正在尝试使用 redux-form 执行 API 更新调用。在initialize 的帮助下,我可以在编辑表单中获取数据。它运作良好。除非用户刷新浏览器。在这种情况下,我无法在 initialize 中获取数据,因为它在 props/states 中不可用。
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..>
);
我确实尝试过 React 生命周期方法 componentWillMount 来获取数据,但它似乎不起作用。
当用户刷新浏览器时,它会抛出错误:
未捕获的类型错误:无法读取 null 的属性“名称”
当用户刷新页面时,我应该如何解决获取/保留数据的问题?
【问题讨论】:
标签: reactjs react-redux redux-form react-redux-form