Correct state handling in <FormBuilder> component

This commit is contained in:
Ingo Schommer 2016-04-07 17:15:14 +12:00
parent 874146afda
commit ab874a0c8d

View File

@ -94,8 +94,10 @@ export class FormBuilderComponent extends SilverStripeComponent {
super(props); super(props);
this.formSchemaPromise = null; this.formSchemaPromise = null;
this.isFetching = false; this.state = { isFetching: false };
}
componentDidMount() {
this.fetch(); this.fetch();
} }
@ -111,7 +113,7 @@ export class FormBuilderComponent extends SilverStripeComponent {
fetch(schema = true, state = false) { fetch(schema = true, state = false) {
const headerValues = []; const headerValues = [];
if (this.isFetching === true) { if (this.state.isFetching === true) {
return this.formSchemaPromise; return this.formSchemaPromise;
} }
@ -129,11 +131,11 @@ export class FormBuilderComponent extends SilverStripeComponent {
}) })
.then(response => response.json()) .then(response => response.json())
.then(json => { .then(json => {
this.isFetching = false; this.setState({ isFetching: false });
this.props.actions.setSchema(json); this.props.actions.setSchema(json);
}); });
this.isFetching = true; this.setState({ isFetching: true });
return this.formSchemaPromise; return this.formSchemaPromise;
} }