24
loading...
This website collects cookies to deliver better user experience
createContext()
function from react
, and create a context. Then export it, So that it can be used by other components. And through a provider, we will pass in all the data as value.children
of this context so that every component can use the data.import React, { createContext } from "react";
import useFirebase from "../../hooks/useFirebase";
export const AuthContext = createContext();
const AuthProvider = ({ children }) => {
const allContexts = useFirebase();
return (
<AuthContext.Provider value={allContexts}>
{children}
</AuthContext.Provider>
);
};
export default AuthProvider;
useContext()
function from react
, and pass into the context data and return
it, so we can be used it by other components.import { useContext } from "react";
import { AuthContext } from "../contexts/AuthProvider/AuthProvider";
const useAuth = () => {
const auth = useContext(AuthContext);
return auth;
};
export default useAuth;
function App() {
return (
<AuthProvider>
<Booking />
<Dashboard />
</AuthProvider>
);
}
export default App;