I want to observer when window stop resizing, cause currently if i listen to the resize
event on window
, i could only listen to resizing change
but not knowing when resizing stops. I checked the event
parameter in resizing callback, but did not find and helpful information.
Below is the code i'm trying to complete:
import React, { useState, useEffect } from "react";
export default function App() {
const [windowResizing, setWindowResizing] = useState(false);
const handleWindowResize = e => {
setWindowResizing(true);
};
useEffect(() => {
window.addEventListener("resize", handleWindowResize);
return () => window.removeEventListener("resize", handleWindowResize);
}, []);
return <div>{JSON.stringify({ windowResizing })}</div>;
}
But this does not work, since windowResizing
will keep being true
after resizing begins, even i already stops resizing.
So is there any way to observe when window stop resizing and i can then call setState
based on that?