optimize with useMemo

This commit is contained in:
proddy
2024-10-08 22:49:44 +02:00
parent 87cea5865a
commit 5d69ce18a2

View File

@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from 'react';
import type { FC } from 'react'; import type { FC } from 'react';
import { redirect } from 'react-router-dom'; import { redirect } from 'react-router-dom';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
@@ -67,17 +67,15 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
void refresh(); void refresh();
}, [refresh]); }, [refresh]);
// cache object to prevent re-renders
const obj = useMemo(
() => ({ signIn, signOut, me, refresh }),
[signIn, signOut, me, refresh]
);
if (initialized) { if (initialized) {
return ( return (
// TODO useMemo? <AuthenticationContext.Provider value={obj}>
<AuthenticationContext.Provider
value={{
signIn,
signOut,
me,
refresh
}}
>
{children} {children}
</AuthenticationContext.Provider> </AuthenticationContext.Provider>
); );