import React, { useMemo } from 'react'
import Skeleton from '../skeleton'
import { SkeletonProps } from './skeleton-types'

const useSkeleton = (
  component: React.ReactNode,
  loading?: boolean,
  props?: SkeletonProps
): React.ReactNode => {
  return useMemo(() => {
    if (loading || component === undefined) {
      return <Skeleton {...props} />
    }
    return component
  }, [loading, component, props])
}

export default useSkeleton
