I am working on a React project and following MERN boiler plate.In my project I am using socket.io for updating component state in real time. What is the most appropriate way of defining socket object in MERN so that it can be accessed through out application P.S : each component is defined in a separate .js file
Justin Rich
Solutions Architect
Im sort of surprised you havent received an answer yet, so im going to chime in. Im obviously not the best person to answer this, but here goes.
So in any of the docs i've read in regards to react it says to keep things as high as possible in the chain so that lower level components are pure, which decreases the odds of bugs being there. This means that you should have one high level container that not only holds your compoents, but also maintains state here which is then passed down to the child components. As far as the function to use, it should probably be in the compoentDidMount.
sorry i cant be of more help, hopefully someone else chimes in