Skip to content

Commit

Permalink
feat: add context barbeiro
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Mar 30, 2022
1 parent f878a86 commit 1f46fcd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/contexts/Barbeiro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createContext, useContext, useState } from 'react';

import { UserMetadata } from 'types/IContext';

interface IBarbeiroContext {
barbeiro: UserMetadata | undefined;
// eslint-disable-next-line no-unused-vars
setBarbeiro: (barbeiro: UserMetadata) => void;
}

const Barbeiro = createContext({} as IBarbeiroContext);

export function BarbeiroProvider({ children }: any) {
const [barbeiro, setBarbeiro] = useState<UserMetadata>();

return (
<Barbeiro.Provider
value={{
barbeiro,
setBarbeiro,
}}
>
{children}
</Barbeiro.Provider>
);
}

export function useBarbeiro() {
const context = useContext(Barbeiro);
if (!context) {
throw new Error('useBarbeiro must be used within a BarbeiroProvider');
}
return context;
}

0 comments on commit 1f46fcd

Please sign in to comment.