Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
branch-context-stream-context-blog
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}>
{children}
</BranchContext.Provider>
);
};
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.