ActionCable not working in react component

Viewed 186

I have an action cable that worked perfectly in the App.js component, but when I changed the action cable to another component that renders after the App.js the action cable stopped working. The console does not show errors. The action cable should change the state value.

Here is a piece of my action cable in the component that is not the App.js

const [state, setState] = useState([]);

useEffect(() => {
  costumerInfo();
}, []);

function costumerInfo() {
  return new Promise((resolve) => {
    setTimeout(() => {
      const cable = ActionCable.createConsumer(`wss://directionDummy.com/`);
      const sub = cable.subscriptions.create("Threads", {
        received: handleReceiveNewName,
      });
      handleClose();
      resolve();
    }, 3000);
  });
}

const handleReceiveNewName = (m) => {
  setState(m);
};
0 Answers
Related