import React, { Component, ComponentType } from 'react'
import { preloadImage } from '../utils'

export default function preload<Props>(imgList: Array<string>) {
  return function preloadHoc(OriginComponent: ComponentType<Props>) {

    return class PreloadWrapper extends Component<Props> {
      public componentWillMount() {
        preloadImage(imgList)
      }
      public render() {
        return <OriginComponent {...this.props} />
      }
    }
  }
}
