mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 20:51:11 +10:00
switch to nx monorepo
This commit is contained in:
23
apps/client/src/features/user/user-provider.tsx
Normal file
23
apps/client/src/features/user/user-provider.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { useAtom } from 'jotai';
|
||||
import { currentUserAtom } from '@/features/user/atoms/current-user-atom';
|
||||
import React, { useEffect } from 'react';
|
||||
import useCurrentUser from '@/features/user/hooks/use-current-user';
|
||||
|
||||
export function UserProvider({ children }: React.PropsWithChildren) {
|
||||
const [, setCurrentUser] = useAtom(currentUserAtom);
|
||||
const { data, isLoading, error } = useCurrentUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (data && data.user) {
|
||||
setCurrentUser(data);
|
||||
}
|
||||
}, [data, isLoading, setCurrentUser]);
|
||||
|
||||
if (isLoading) return <></>;
|
||||
|
||||
if (error) {
|
||||
return <>an error occurred</>;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user