Skip to content

Handling side effects depending on "isValid" field state #344

@ekozhura

Description

@ekozhura

Hey, I'm trying to run some side effects like logging when field state is changing after validation. I use mobx reactions (maybe there are better options) to observe isValid property and react on it:

  const logger = reaction(
    () => this.props.field.isValid,
    isValid => {
      const { name } = this.props.field;
      LoggerService(`${name} status: ${isValid ? LoggerStatus.ValueOk : LoggerStatus.ValueError}`);
    }
  );

Works perfectly fine but on form submit some kind of validation reset is happening:

field1 status: ok
field1 status: error
field2 status: ok
field2 status: error

Whereas I prefer to get actual field state on submit:

field1 status: error
field2 status: error

I suspect I'm doing something wrong, maybe you can suggest a better solution?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions