How to setState from reactjs non component function of a class component

18 views Asked by At

This is my peer.js file code to setup peer

export const peer = new Peer(peerid, {
      path: "/myapp",
      host: "localhost",
      port: "9000"
    });
peer.on('connection', function (c) {
    setSomeData('ABCD')//This is from some functional or class component
}

In a peer.on listener, I want to setState of class/function component, i can use usecontext but it will rerender peer.js as well. The purpose is that i want to add more listener to peer.js, and they will trigger particular states.

0

There are 0 answers