Created
May 22, 2021 17:01
-
-
Save Sergioamjr/0addf04d90539c53420c5cbf62c34eb2 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 { useContext, createContext } from "react"; | |
// Nosso contexto | |
const UserContext = createContext({ name: "" }); | |
// Componente que recebe e atualiza o valor de name | |
export function UserContextProvider({ name, children }) { | |
return <UserContext.Provider value={name}>{children}</UserContext.Provider>; | |
} | |
// Custom hook para pegar o valor atual | |
export default function useUserContext() { | |
return useContext(UserContext); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment