title: How to make count increment with Websocket api using React JS
body: <p>I have notification icon button which has count so i want the count to be incremented whenever new data is fetched using Websocket api,how can i achieve that,and how make this websocket as component which will recieve prop</p>
  <pre><code>import React from &quot;react&quot;;
  import { useState, useEffect } from &quot;react&quot;;
  const Websocket = (props) =&gt; {
    const [count, setCount] = useState([]);
    useEffect(() =&gt; {
      let ws = new Websocket(&quot;wss://example.com&quot;);
      ws.onopen = () =&gt; {
        console.log(&quot;connection open&quot;);
       
      };
      ws.onmessage = (e) =&gt; {
        setCount(e.data);
      };
    });
  };
  
  export default Websocket;
  </code></pre>