Skip to content

Race condition: onschemaChange get called before the data gets properly loaded #18

@Wytzepakito

Description

@Wytzepakito

Thank you for the great package!!!

I'm using the JsonSchemaEditor like this:

  handleChange(schema) {    
    if (!isEqual(JSON.parse(schema), JSON.parse(this.props.data))) {
        console.log(this.props);
        this.props.onChange(schema);
      }
  }
      <JsonSchemaEditor
        onSchemaChange={this.handleChange}
        data={JSON.parse(this.props.data)}
      />

Basically the schema gets stored in a state. This state gets updated in case the user edits the currently loaded schema.
There is a race condition that occurs where the state gets updated with the fetched schema, however the schema inside the editor is still empty. The handleChange function gets called and the empty schema overwrites the state. Leaving the SchemaEditor to be empty.

For some reason the handleChange function before the data prop is properly loaded inside the JsonSchemaEditor component.

I hope someone can help with this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions