We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When using useEffect and useDocument infinite loops.
This is a custom hook I have to have up to date use data.
export function useUserData(): UseUserDataReturn { const { data: session, status } = useSession(); const documentRef = useCallback(() => { return session?.user?.id ? doc(db, 'users', session.user.id) : null; }, [session?.user?.id]); const options = useMemo(() => ({ snapshotListenOptions: { includeMetadataChanges: true }, }), []); const [value, loading, error] = useDocument(documentRef(), options); const userData = value?.data() as User | null; return { session, status, userData, loading, error }; }
If I create a separate state and use useEffect to update that state when userData changes it causes an infinite loop. Here's an example.
const { userData } = useUserData(); const [ cart, setCart ] = useState<string[]>([]); useEffect(() => { if (!userData) return; setCart( Object.keys( userData.cart ) ); }, [ userData ]);
Am I doing something wrong? Is there a way to fix this?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When using useEffect and useDocument infinite loops.
This is a custom hook I have to have up to date use data.
If I create a separate state and use useEffect to update that state when userData changes it causes an infinite loop. Here's an example.
Am I doing something wrong? Is there a way to fix this?
The text was updated successfully, but these errors were encountered: