Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource custom dns refetch instance details #510

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Stack } from "@mui/material";
import { useMemo } from "react";
import { useEffect, useMemo } from "react";
import PropertyTable from "./PropertyTable";
import CustomDNS from "./CustomDNS";
import Card from "src/components/Card/Card";
Expand All @@ -15,6 +15,10 @@ function ResourceCustomDNS(props) {
refetchInstance,
} = props;

useEffect(() => {
refetchInstance();
}, []);
Comment on lines +18 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving the useEffect implementation.

The current implementation has several potential issues:

  1. refetchInstance should be included in the dependency array to comply with React hooks exhaustive deps rule
  2. Consider adding error handling for the refetch operation
  3. Consider adding a cleanup function to handle unmounting

Apply this diff to improve the implementation:

  useEffect(() => {
-   refetchInstance();
+   let mounted = true;
+   const fetchData = async () => {
+     try {
+       if (mounted) {
+         await refetchInstance();
+       }
+     } catch (error) {
+       console.error('Failed to fetch instance details:', error);
+     }
+   };
+   fetchData();
+   return () => {
+     mounted = false;
+   };
-  }, []);
+  }, [refetchInstance]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
refetchInstance();
}, []);
useEffect(() => {
let mounted = true;
const fetchData = async () => {
try {
if (mounted) {
await refetchInstance();
}
} catch (error) {
console.error('Failed to fetch instance details:', error);
}
};
fetchData();
return () => {
mounted = false;
};
}, [refetchInstance]);


const primaryResourceName = globalEndpoints?.primary?.resourceName;
const primaryResourceEndpoint = globalEndpoints?.primary?.endpoint;

Expand Down
Loading