I made a socket connection in react and pass data as well as socket instance in the context API values. I was able to get data and instances in my child component. Now what I tried is to send a message to the socket from the child component using the socket instance(which I passed through context).
I used send method to pass data to socket but looks like it didn't work. I checked the connection in postman and everything seems working.
const ViewNotification=(props) =>
{
var notificationData=useContext(NotificationContext);
const token=localStorage.getItem("provider__token") ||
sessionStorage.getItem("provider__token");
var io=notificationData.method;
const id=queryString.parse(props.location.search).id
if(io.readyState === 1)
{
io.send({token:token,text:id});
io.onmessage=(data) =>
{
console.log(data);
}
}
else
{
console.log("Socket closed.....")
}