Skip to content

Instantly share code, notes, and snippets.

@dandelionadia
Created April 8, 2020 14:48
Show Gist options
  • Save dandelionadia/900fd7f476d7313d3ca485476e835fcd to your computer and use it in GitHub Desktop.
Save dandelionadia/900fd7f476d7313d3ca485476e835fcd to your computer and use it in GitHub Desktop.
import React, { useEffect, useRef, useContext } from "react";
import { AuthContext } from "../../context/auth-context";
export const Cockpit = (props) => {
const authContext = useContext(AuthContext);
console.log(authContext.authenticated);
return (
<>
<button onClick={authContext.login}>Log in</button>
</>
);
};
____________________
import React from "react";
//createContext({default value})
//the default value will apply when you don't set any other value.
export const AuthContext = React.createContext({
authenticated: false,
login: () => {},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment