Skip to content
Snippets Groups Projects
Commit 32b918ab authored by Chif Gergő's avatar Chif Gergő
Browse files

Create ClientContext

parent 6fae700b
No related branches found
No related tags found
2 merge requests!19fix type imports,!8Refactor structure
import React, { createContext } from 'react';
import { Client, createClient } from '../client/client';
export type ClientContextType = {
client: Client;
};
export const ClientContext = createContext<ClientContextType>({
client: createClient(),
});
type ClientContextProviderProps = {
baseUrl?: string;
};
export const ClientContextProvider: React.FC<ClientContextProviderProps> = ({
children,
baseUrl = '',
}) => {
return (
<ClientContext.Provider
value={{
client: createClient(baseUrl),
}}
>
{children}
</ClientContext.Provider>
);
};
export * from './ClientContext';
export * from './UserContext';
import { useContext } from 'react';
import { ClientContext } from '../context';
import type { ClientContextType } from '../context';
function useClientContext(): ClientContextType {
const clientContext = useContext(ClientContext);
if (!clientContext) {
throw new Error('You must use `ClientContextProvider` to access the `ClientContext`.');
}
return clientContext;
}
export default useClientContext;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment