I am using simple-peer
library for making a chat application.
When I receive message from the other peer connection using peer.on('data' => (data) => { console.log(data) })
, it is called multiple times and I receive the message multiple times.
Asked
Active
Viewed 235 times
0

Abhishek Raghav
- 1
- 3
-
Where are you calling `peer.on()`? Is it in a `useEffect()` hook? – Calvin Jul 04 '21 at 17:48
-
No, I have called it outside. – Abhishek Raghav Jul 05 '21 at 16:21
-
Are you using function components? Is the call part of a callback, or is it just something that's in your function? If it's the latter, `peer.on()` will be called on every render. – Calvin Jul 05 '21 at 18:29
-
Ok thanks @Calvin . I am actually using ```peer.on()``` inside a functional component. – Abhishek Raghav Jul 06 '21 at 14:58