Every example I've seen of React
context is like this:
theme-context.js
// Make sure the shape of the default value passed to
// createContext matches the shape that the consumers expect!
export const ThemeContext = React.createContext({
theme: themes.dark,
toggleTheme: () => {},
});
Where you're having a file contain an instance of the context. Then you pass it into the component using useContext(ThemeContext)
.
My question is, if you're doing this and it's always a singleton, why don't you simply just import the stuff in the context directly from the singleton so to speak. Basically I'm wondering if there is ever a time where you create more than one instance of your context, such as perhaps for testing you create a new one per test, something like that.