In react there's an easy way to share "information" within several layers of components. This is by using context
import {UserCtx} from "./stores/UserCtx";
<UserCtx.Provider value={new user(info)}>
<SomeComponent />
</UserCtx.Provider/>
And then in some component:
import {UserCtx} from "./stores/UserCtx";
function SomeComponent() {
const userData = React.useContext(UserCtx);
return <div>JSON.stringify(userData)</div>
}
However this requires the context object definition to be visible for all objects. And thus when creating a library of components it cannot really be used?
Say in above "example" SomeComponent
would be a library component, how would I share the context of the main application to the component? Sharing by adding an attribute seems far fetched, at that point I might as well just provide the user (or whatever the context stores) directly?