参考:https://redux-form.com/6.7.0/examples/initializefromstate/
我正在尝试实现一个配置文件表单,该表单使用从api端点获取的初始数据进行更新.
在引用上面的redux-form示例时,我已经能够使示例工作.但是,当我重构它使用compose'initialValues'时,不会插入到字段中.
此代码不起作用,initialValues包含数据但不插入表单字段.
export default compose(
reduxForm({
form: 'initializeFromState',
enableReinitialize : true
}),
connect(state => ({
initialValues: state.profile, // pull initial values from account reducer
}), actions)
)(EditProfile);
Run Code Online (Sandbox Code Playgroud)
但是,此代码的工作原理只是从参考示例稍作修改.'initialValues'也包含数据.
EditProfile = reduxForm({
form: 'initializeFromState',
enableReinitialize: true
})(EditProfile);
EditProfile = connect(
state => ({
initialValues: state.profile,
}),
actions,
)(EditProfile);
export default EditProfile;
Run Code Online (Sandbox Code Playgroud)
它看起来与我相似,但也许我不能使用这样的作品?
我需要访问 responseA 以进一步访问链接请求中的字段值。如何优雅地做到这一点?
axios.get(`/endpoint`)
.then((responseA) => {
// Do something with responseA
return axios.put(signedUrl, file, options);
})
.then((responseB) => {
// Do something with responseA & responseB
})
.catch((err) => {
console.log(err.message);
});
Run Code Online (Sandbox Code Playgroud)
更新:我可能应该提到在我的第一个 .then() 中我返回了另一个网络请求。它必须按顺序发生。