Created
May 12, 2020 22:32
-
-
Save wevertoum/415a26c9ccb605291acdd14e34304391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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