Our React applications are composed of many small components or modules. The components that we write will sometimes be dependent on each other. As...
For further actions, you may consider blocking this person and/or reporting abuse
I have few remarks to your article:
Typical module system in NodeJS, not JavaScript. This doesn't work that way on the browser.
Even in NodeJS, this is not a best practice, as it can be easily broken. Check out this article.
And one more: I think it's not a good idea to use the Context API for injecting things like a websocket service. Context API is for passing
data
through the component tree, I guess that passing complicated objects out there might create problems (i.e. performance ones). For things like this - why not just import it?Hey Jakub, that is a great feedback. Thank you for the input. I will do some more research on the module system. I have been injecting services like simple websockets and firebase real time DB instances through Context. And I totally agree if not careful these will lead to memory leaks. I will do some more research on these as well and definitely address these caveats. Good feedback though. Loved it :)
Would love to hear about the caveats & how to address them :)
I would agree with Jakub comment that the Context API is better used for passing data. Also, have you consider using custom hook for reuse those thing?
This post is now quit old and yes custom hooks are a straight forward way to do this.