我想知道这种情况是否可能:
const MyComponent = ({props1, props2}) => (
<div >
// SOME STUFF using props1 and props2
</div>
);
const ReduxFormWithMyComponent = reduxForm({
form: 'test',
onSubmitFail: (errors, dispatch, submitError, props) => {
// here I would like to have access to props1 and props2 like:
// const { props1, props2 } = props;
},
onSubmitSuccess: (result, dispatch, props) => {
// same here:
// const { props1, props2 } = props;
},
})(MyComponent);
因此,基本上,我需要根据props1
和props2
回调中onSubmitFail
和onSubmitSuccess
的值来做一些条件式的东西。
根据documentation,我没有看到任何详细信息。
谢谢
答案 0 :(得分:0)
我找到了有效的解决方案。对于遇到相同问题的人可能很有用。
在这里:
您的组件必须像这样的形状:
const MyComponent = ({handleSubmit, props1, props2}) => (
<div >
<form
onSubmit={handleSubmit(data => myCustomSubmitFonction(data, {props1, props2}))}
>
// SOME STUFF using props1 and props2
</form>
</div>
);
根据reduxform documentation,您可以作为道具handleSubmit
从reduxform传递。结果,您可以根据需要为handleSubmit
函数提供参数(在我的情况下为props1
和props2
)
然后,myCustomSubmitFonction
需要返回它:
myCustomSubmitFonction(reduxFormData, myCustomData) {
// reduxFormData useless in my case
return myCustomData;
}
现在,我可以通过props1
(第一个参数)访问props2
和result
:
const ReduxFormWithMyComponent = reduxForm({
form: 'test',
onSubmitFail: (errors, dispatch, submitError, props) => {
const { props1, props2 } = result;
// Yay !!
},
onSubmitSuccess: (result, dispatch, props) => {
const { props1, props2 } = result;
// Yay !!
},
})(MyComponent);