-
Notifications
You must be signed in to change notification settings - Fork 1
proper way to add onChange event while keeping redux-forms/actions? #24
Comments
thanks! much nicer implementation :) . thanks 👍 |
another question. how could i listen to changes in a form? i could create middleware and listen for "@@redux-forms/FIELD_CHANGE" and then use the getValues() selector and dispatch a new action called FORM_CHANGED? do you think thats best? in docs you mention don't use form action names as they may have breaking changes. thanks for all your help |
or
|
I haven't thought about listening for changes of the whole form. The only kinda clean way I can think of is comparing current and previous values in // ...code
componentWillReceiveProps(nextProps) {
if (this.props.values !== nextProps.values) {
// form changed, do stuff
}
}
// ...code
export default connect(state => ({
values: getValues('yourform', state),
}))(YourForm); I will consider introducing an API for this use case if this solution turns out to be non-practical. With that said, I try to keep any change listeners per-field, thus making something like you provided the first example of - I supply an optional It makes you pass the callback to all your fields, which may seem not very DRY, but is explicit and guaranteed to work. Try both approaches and let me know! |
adding a onChange handler to my input seems to remove the redux-forms/actions
how do you recommend having both? using middleware to intercept the action? use a thunk to dispatch the redux-forms/action from my onChange action?
or maybe a new function to pass into the component like "watchValue"?
thoughts?
im basically trying to call a api whenever my input field changes. i was using onBlur... but i would like a more instant feel so im using onChange with a debounce
something like this is what i did... which i guess works? but monkeypatching
The text was updated successfully, but these errors were encountered: