Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import React, { createContext, useState } from "react";
// create a React context for managing global state
const BranchContext = createContext();
// access context value through a consumer component
export const BranchConsumer = BranchContext.Consumer;
// save data and share with children through provider component
const BranchProvider = ({ children }) => {
const [contextData, setContextData] = useState({});
const contextValue = { contextData, setContextData };
return (
<BranchContext.Provider value={contextValue}>
export default BranchProvider;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.