Skip to content

Commit 1234ef5

Browse files
committed
wrap validator with useCallback
1 parent 7295142 commit 1234ef5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/auth/AuthorizationZone.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// https://opensource.org/licenses/MIT
55

66
import { Auth, User } from "firebase/auth";
7-
import { ReactNode, useEffect, useState } from "react";
7+
import { ReactNode, useCallback, useEffect, useState } from "react";
88
import { useUser } from ".";
99

1010
export type AuthorizationZoneValidator = (
@@ -27,15 +27,17 @@ export const AuthorizationZone = ({
2727
const user = useUser(auth);
2828
const [success, setSuccess] = useState(false);
2929

30+
const _validator = useCallback(validator, [validator]);
31+
3032
useEffect(() => {
31-
const taskOrVal = validator(user);
33+
const taskOrVal = _validator(user);
3234

3335
if (taskOrVal instanceof Promise) {
3436
taskOrVal.then(setSuccess);
3537
} else {
3638
setSuccess(taskOrVal);
3739
}
38-
}, [user, validator]);
40+
}, [user, _validator]);
3941

4042
return success ? onSuccess(user) : onFailure(user);
4143
};

0 commit comments

Comments
 (0)