ShouldUpdateState hook

In some cases you might need to postpone state update to some time for example until field is valid. In this case you can do use shouldUpdateState method

 componentDidMount() {
    this.formStateManager = Store.store.select(['form']).form
        .bind(this.form.current)
        .addCustomFormElements([this.customFormElement.current])
        .shouldUpdateState(this.shouldUpdateState)
        .onChange(state => this.forceUpdate())
        .sync();
}
shouldUpdateState = (params: ShoulUpdateStateParams) => {
    return true;
}

ShouldUpdateStateParams:

  • form: HTMLFormElement - form that has being synced

  • formElements: FormElement[] - all form elements that are being synced

  • target: HTMLElement | CustomFormElement - current html element or custom form element

  • state: any - state before update

  • currentValue: any - current field value

  • value: any - target value

Last updated