import React, { Suspense } from 'react'

interface importProps {
  action: any
  loading?: React.ReactNode
}

export default function LazyImport(props: importProps) {
  const { action, loading } = props
  const LazyComponent = React.lazy(() => action as any)

  return (porps: any) => {
    return (
      <div>
        <Suspense fallback={loading || <div>Loading...</div>}>
          <LazyComponent {...porps} />
        </Suspense>
      </div>
    )
  }
}
