Skip to content

Commit

Permalink
unmount ImgCancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyxu committed Jan 18, 2024
1 parent aeced60 commit 06de620
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ui/packages/common/components/ImgCancelable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ const useGetState = (initiateState) => {
return [state, setState, getState];
};

export default ({ isNative, src, inView, renderImg, renderSkeleton }) => {
const [url, setUrl] = useState();
export default ({ isNative, src, inView = true, renderImg, renderSkeleton }) => {
const [url, setUrl, getUrl] = useGetState();
const [loaded, setLoaded, getLoaded] = useGetState(0);
const controller = useRef(new AbortController());
useEffect(() => {
return () => {
// console.log("unmount", src);
controller.current.abort();
}
}, []);
useEffect(() => {
const l = getLoaded();
// console.log(src, inView, l);
if (inView && l === 0) {
setLoaded(1);
// console.log(src, "fetch");
// console.log("mount", src);
fetch(src, {
method: 'get',
signal: controller.current.signal,
Expand Down

0 comments on commit 06de620

Please sign in to comment.