<commit_before>import React, { Component } from 'react';
import { object, func } from 'prop-types';
import createHoc from './createHOC';

export default createHoc(getAwait => class Await extends Component {

  static getDerivedStateFromProps(nextProps) {
    const awaiting = getAwait(nextProps)();

    return {
      awaiting,
      loading: true,
      result: null,
      onDone: func,
    };
  }

  state = {
    loading: false,
    result: null,
  };

  setResult = (error, result) => {
    this.setState({ result, error, loading: false });
  };

  componentDidMount() {
    this.state.awaiting
      .then(result => this.setResult(null, result))
      .catch(error => this.setResult(error));
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.loading && !this.state.loading && this.props.onDone) {
      this.props.onDone(this.state.error, this.state.result);
    }
  }

  componentWillUnmount() {
    this.setResult = () => {};
  }

  componentDidCatch(error) {
    console.error(error);
  }

  render() {
    const { result, error, loading } = this.state;<commit_msg>fix withAwait<commit_after>import React, { Component } from 'react';
import { object, func } from 'prop-types';
import createHoc from './createHOC';

export default createHoc(getAwait => class Await extends Component {

  state = {
    loading: false,
    result: null,
    error: null,
  };

  setResult = (error, result) => {
    this.setState({ result, error, loading: false });
  };

  componentDidMount() {
    this.setState({
      loading: true,
      result: null,
    });
    getAwait(this.props)()
      .then(result => this.setResult(null, result))
      .catch(error => this.setResult(error));
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.loading && !this.state.loading && this.props.onDone) {
      this.props.onDone(this.state.error, this.state.result);
    }
  }

  componentWillUnmount() {
    this.setResult = () => {};
  }

  componentDidCatch(error) {
    console.error(error);
  }

  render() {
    const { result, error, loading } = this.state;
{'fraction_non_alphanumeric': 0.14656415185007207, 'fraction_numerical': 0.0, 'mean_word_length': 3.1146245059288535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7344284', 'n_tokens_mistral': 678, 'n_tokens_neox': 663, 'n_words': 138}