Skip to content

Commit b065db4

Browse files
committed
fix: handling how useEffect is run in strict mode
1 parent 1df27eb commit b065db4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

react-static-web-apps-auth/src/ClientPrincipalContext.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ const ClientPrincipalContextProvider = ({
4040
const [swaCookie, setSwaCookie] = useState<string | null>(null);
4141

4242
useEffect(() => {
43+
const abortController = new AbortController();
4344
const run = async () => {
4445
try {
45-
const res = await fetch("/.auth/me");
46+
const res = await fetch("/.auth/me", {
47+
signal: abortController.signal,
48+
});
4649
const json: {
4750
clientPrincipal: ClientPrincipal | null;
4851
} = await res.json();
@@ -66,6 +69,8 @@ const ClientPrincipalContextProvider = ({
6669
};
6770

6871
run();
72+
73+
return () => abortController.abort();
6974
}, []);
7075

7176
return (

0 commit comments

Comments
 (0)