Skip to content

Commit

Permalink
fix: wait for api to load
Browse files Browse the repository at this point in the history
  • Loading branch information
sasza2 committed Jan 26, 2024
1 parent d8cbf3d commit 3cd0e7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-grid-panzoom",
"version": "1.4.0",
"version": "1.4.1",
"description": "React grid component for pan and zoom with possibility to moving and selecting elements inside",
"keywords": [
"react",
Expand Down
16 changes: 13 additions & 3 deletions src/hooks/useApiLoaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ const useApiLoaded = () => {
const [apiLoaded, setApiLoaded] = useState(false);

useEffect(() => {
if (apiLoaded || !panZoomRef.current) return;
if (apiLoaded) return;

setApiLoaded(true);
}, [apiLoaded, panZoomRef.current]);
const checkAPI = () => {
if (panZoomRef.current) setApiLoaded(true);
}

checkAPI()

const waitForAPI = setInterval(checkAPI, 10)

return () => {
clearInterval(waitForAPI)
}
}, [apiLoaded]);

return apiLoaded;
};
Expand Down

0 comments on commit 3cd0e7a

Please sign in to comment.