import React, { useState } from 'react'
import { Spin, Table } from 'antd'

export default props => {
  const [loading, setLoading] = useState(false)

  const pagination = {
    ...props.pagination,
    onChange: (page, pageSize) => {
      setLoading(true)
      props.onPageChange(page, pageSize).then(() => setLoading(false)).catch(() => setLoading(false))
    }
  }

  const { onPageChange, ...tableProps } = props

  return (
    <Spin spinning={loading} delay={300} tip="请稍候...">
      <Table pagination={pagination} {...tableProps} />
    </Spin>
  )
}
