import React, { useEffect,useState,useMemo } from 'react';



const useImageLoader=(img_src)=>{
  const [src,setSrc] = useState('');
  useEffect(() => {
    if(img_src===src)return;
    if(!img_src)return;
    let img = new Image();
    img.onload = () => {
      setSrc(img_src);
    };
    img.onerror = () => {
      setSrc('');
      console.log(`图片加载失败:${img_src}`)
    };
    img.src = img_src;
  }, [img_src]);

  const actions=useMemo(()=>{
    return src;
  },[src]);
  return actions;
}

export default useImageLoader;
