Files
bigcapital/src/components/Dashboard/AuthenticatedUser.js
2021-09-21 17:13:53 +02:00

29 lines
741 B
JavaScript

import React from 'react';
import { useUser } from 'hooks/query';
import withAuthentication from '../../containers/Authentication/withAuthentication';
const AuthenticatedUserContext = React.createContext();
function AuthenticatedUserComponent({ authenticatedUserId, children }) {
const { data: user, ...restProps } = useUser(authenticatedUserId);
return (
<AuthenticatedUserContext.Provider
value={{
user,
...restProps,
}}
children={children}
/>
);
}
export const AuthenticatedUser = withAuthentication(
({ authenticatedUserId }) => ({
authenticatedUserId,
}),
)(AuthenticatedUserComponent);
export const useAuthenticatedUser = () =>
React.useContext(AuthenticatedUserContext);