I am transferring the reduction form to the latest version 6.0.0rc3. In this version, the array of "fields" was gone and replaced by the Field component (see http://redux-form.com/6.0.0-rc.3/docs/MigrationGuide.md/ ). I used the default onBlur function extension in v5 as follows:
const { user_zipcode } = this.props.fields; onChange={ val => user_zipcode.onChange(this._handleZipcodeChange(val)) }
However, the new version of this can no longer be done, because this.props.fields does not exist.
From what I found in the docs, a new way would be to create a component for each form field that has an excellent function, and extend the onBlur function:
_onBlur() { // my custom blur-function } render() { const { input, touched, error } = this.props; return ( <input className={styles.input} {...input} onBlur={() => { // 2 functions need to be called here this._onBlur(); input.onBlur(); }} /> ); }
This is fine, except that I need to create a new element for each field that should do something else when a blur event occurs. In some fields, I have to make an API call that I make by sending an action. For example, I have to do this to get the address. In these components, I have to connect my store, so it connects many times.
I tried passing my custom function from the parent to the Field component, for example:
<Field type="text" name="user_zipcode" component={Zipcode} onBlurFunction={this._myBlurFunction} />
and get both functions in my component from the props:
... onBlur={() => { input.onBlurFunction(); input.onBlur(); }} ...
This did not work correctly due to the new React warning .
Is there a better way to do this?