{"size": 588, "ext": "js", "max_stars_repo_path": "src/support/hooks/useHandle.js", "max_stars_repo_name": "geekape/ruanshu-react-components", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/support/hooks/useHandle.js", "max_issues_repo_name": "geekape/ruanshu-react-components", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/support/hooks/useHandle.js", "max_forks_repo_name": "geekape/ruanshu-react-components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.5, "max_line_length": 71, "alphanum_fraction": 0.6156462585}
import React, { useState } from 'react';
import { request } from '../utils/request';

export default () => {
  const [isLoading, setLoading] = useState(false);
  const [isError, setError] = useState(false);

  const onHandle = async (params, callback) => {
    setError(false);
    setLoading(true);
    try {
      const response = await request({ showMessage: true, ...params });
      if (callback) callback(response);
      return response;
    } catch (error) {
      setError(true);
    } finally {
      setLoading(false);
    }
  };

  return { isLoading, isError, onHandle };
};
