Skip to content

Instantly share code, notes, and snippets.

@Sergioamjr
Created May 22, 2021 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sergioamjr/0addf04d90539c53420c5cbf62c34eb2 to your computer and use it in GitHub Desktop.
Save Sergioamjr/0addf04d90539c53420c5cbf62c34eb2 to your computer and use it in GitHub Desktop.
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