inputlogic / elements

Dependable UI Components for (P)React Apps
0 stars 0 forks source link

Form erases custom values set in store. #110

Closed adriaanwm closed 4 years ago

adriaanwm commented 4 years ago

Say I have myForm and have some dynamic value that is from an element outside of the form (like a list of items with checkboxes that you're selecting). I assumed I could just set the state at ['myForm', 'values', 'myField'] to that value and it would get included in onSubmit. Unfortunately, form uses

  componentDidUpdate () {
    if (!equal(this.state, storeRef.getState()[this.props.name])) {
      storeRef.setState({ [this.props.name]: this.state })
    }
  }

to keep store updated with local state, and this erases the value I set for myField

staydecent commented 4 years ago

If you want to PR this, I'd accept. But, I'd like to deprecate in favor of a hook based approach.

Also, I'd waffle on calling this a bug. Forms usually control their own data, under 1 form. Including data from outside of the form UI is more of an enhancement than a bug. For instance, this is not supported by redux-forms.

staydecent commented 4 years ago

@adriaanwm In the future (or if you want to migrate), this use-case is handled by the preProcess prop for useForm