I have a form input validation function that just returns an empty errors object or a populated errors object.
const validate = function validateSomeInput({ field1, field2 }) {
const errors = {}
// some logic
return errors
}
export default validate
Is there a way to hook an action creator into this function?
This is what I am trying to achieve:
const validate = function validateSomeInput({ field1, field2 }) {
const errors = {}
// some logic
props.onErrorEvent('do something')
return errors
}
export default connect(null, { onErrorEvent })(validate)
My issue is that since it's not a class, I don't have access to this.props, and I have never tried to make a container before that doesn't render any JSX.
I also can't create a callback into the parent because the validate function is controlled by Redux-Form.
It's used like this in the parent container:
export default compose(
connect(mapStateToProps, {
onErrorEvent, // this is the action creator I want to access from validate
onLoginSuccess,
}),
graphql(LOGIN_MUTATION),
reduxForm({
validate, // how do I get an action creator into this function?
form: 'LoginForm',
}),
)(LoginForm)
Is it possible to wire an action creator into a utility function that doesn't render JSX and can't callback to parent?
I'd also like to know if this is bordering into any kind of horrendous anti-pattern territory because I can't find any information about allowing random utility functions to call action creators.
I didn't see a solution with bindActionCreators, but maybe I just didn't see how it relates to this scenario.
Is there a way I can create a HOC in this scenario?