Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wytzepakito opened this issue Oct 9, 2023 · 0 comments

Comments

@Wytzepakito
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant