import React from 'react';
import useDataApi from 'utils/useDataApi';

const DataApi = function() {
    const [{ isLoading, isError, progress, data }, doUpload] = useDataApi(
        'https://www.mocky.io/v2/5cc8019d300000980a055e76',
        {}
    );
    return (
        <div>
            <input
                type="file"
                onChange={(e: any) => {
                    var data = new FormData();
                    data.append('file', e.target.files[0]);
                    doUpload({ data });
                }}
            />
            <div>
                <h3>上传状态</h3>
                <p>{isLoading ? '上传中' : '非上传中'}</p>
                <p>{isError ? '发生错误' : '无错误'}</p>
                <p>上传进度 {progress}%</p>
                <p>结果数据 {JSON.stringify(data, null, 4)}</p>
            </div>
        </div>
    );
};
DataApi.defaultProps = {};
export default DataApi;
