Codeminer42/cm42-central

View on GitHub
app/assets/javascripts/components/forms/AsyncForm.js

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';

class AsyncForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = { loading: false };
    this._handleSubmit = this._handleSubmit.bind(this);
  }

  _handleSubmit(ev) {
    ev.preventDefault();
    this.setState({ loading: true });
    this.props
      .onSubmit(this.props.getFormData())
      .catch(() => this.setState({ loading: false }));
  }

  render() {
    return this.props.children({
      loading: this.state.loading,
      handleSubmit: this._handleSubmit,
    });
  }
}

export default AsyncForm;