简体   繁体   中英

How to play sound Whenever I recieve new notification witj reactJs?

actually I'm working on reactJs project with laravel on backend I want to play sound whenever I recieve notification I tried but I didn't get a solution. this is my code :

  useEffect(() => {
    let statusInterval = setInterval(() => {
    getData();

  }, 10000)
  return () => {
    clearInterval(statusInterval);
  }
  }, [])

  async function getData() {
    let result = await fetch(`${API_ENDPOINT}/api/listComplain`);
    result = await result.json();
    setData(result)
  }

I want also to know if there's another way better that setInterval to get data Thanks in advance for your help.

Classic would have been to use web sockets for this instant notification notices to clients. But this requires some setup and knowledge. Actually I wrote a service that you can POST to it and it will send data (like a string) to the clients, which is what you need. https://rejax.io .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM