Skip to content

Instantly share code, notes, and snippets.

@wevertoum
Created May 12, 2020 22:32
Show Gist options
  • Save wevertoum/415a26c9ccb605291acdd14e34304391 to your computer and use it in GitHub Desktop.
Save wevertoum/415a26c9ccb605291acdd14e34304391 to your computer and use it in GitHub Desktop.
import React, {
createContext,
useState,
Dispatch,
SetStateAction,
} from "react";
import { UsuarioInterface } from "../utils/models/UsuarioInterface";
interface UsuarioLogadoContextProps {
usuarioLogado: UsuarioInterface;
setUsuarioLogado?: Dispatch<SetStateAction<UsuarioInterface>>;
}
const defaultUsuarioLogado = {
usuarioLogado: null,
};
const UsuarioLogadoContext = createContext<UsuarioLogadoContextProps>(
defaultUsuarioLogado
);
export function UsuarioLogadoProvider({ children }) {
const [usuarioLogado, setUsuarioLogado] = useState(null);
return (
<UsuarioLogadoContext.Provider
value={{
usuarioLogado,
setUsuarioLogado,
}}
>
{children}
</UsuarioLogadoContext.Provider>
);
}
export const UsuarioLogadoConsumer = UsuarioLogadoContext.Consumer;
export default UsuarioLogadoContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment