Skip to content

Commit

Permalink
Merge pull request #176 from rit-sse/remove-async-useeffect
Browse files Browse the repository at this point in the history
Removed Async UseEffect causing build warnings
  • Loading branch information
PokeJofeJr4th authored Sep 29, 2024
2 parents e2aaae0 + d9a1386 commit 6c0461b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
8 changes: 5 additions & 3 deletions next/app/go/GoLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ const EditAndDelete: React.FC<GoLinkProps> = ({
const { data: session } = useSession();
const [isOfficer, setIsOfficer] = useState(false);

useEffectAsync(async () => {
const data = await fetchAuthLevel();
setIsOfficer(data.isOfficer);
useEffect(() => {
(async () => {
const data = await fetchAuthLevel();
setIsOfficer(data.isOfficer);
})();
}, []);

if (isOfficer) {
Expand Down
13 changes: 8 additions & 5 deletions next/app/go/MakeNewGoLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSession } from "next-auth/react";
import { useCallback, useEffect, useState } from "react";
import { use, useCallback, useEffect, useState } from "react";
import { CreateGoLinkProps } from "./page";
import { useEffectAsync } from "@/lib/utils";
import { goLinksApi, fetchAuthLevel } from "@/lib/api";
Expand Down Expand Up @@ -44,10 +44,13 @@ export const GoLinkButton: React.FC<CreateGoLinkProps> = ({ fetchData }) => {
};

const [isOfficer, setIsOfficer] = useState(false);
useEffectAsync(async () => {
const data = await fetchAuthLevel();
console.log(data);
setIsOfficer(data.isOfficer);

useEffect(() => {
(async () => {
const data = await fetchAuthLevel();
console.log(data);
setIsOfficer(data.isOfficer);
})
}, []);

if (isOfficer) {
Expand Down
8 changes: 1 addition & 7 deletions next/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ export const isUrlValid = (str: string) => {
"i"
);
return pattern.test(str);
};

export const useEffectAsync = (func: () => any, deps: any[]) => {
return useEffect(() => {
func();
}, deps);
};
};

0 comments on commit 6c0461b

Please sign in to comment.