react-peer icon indicating copy to clipboard operation
react-peer copied to clipboard

state not updating when using useReceivePeerState

Open aroman opened this issue 5 years ago • 1 comments

Hi,

Thanks for the library! I am running into issues with useReceivePeerState and React w/ hooks. It seems that the state variable returned from useReceivePeerState does not update when there is new data on the channel. However, refreshing the page causes the latest data to be loaded. My receiver code is pretty much identical to your sample:

function Recv() {
    const urlParams = new URLSearchParams(window.location.search);
    const brokerId = urlParams.get("broker")!;
    const [state, isConnected, error] = useReceivePeerState<string>(brokerId);
    return (
            <h1>{state}</h1>
    );
}
export default Recv;

So, this code only works when manually refreshing the page. It does cause a re-render when new data is sent from the peer.

aroman avatar May 03 '20 00:05 aroman

Hey mate - thanks for raising this!

Would you be interested in sending over a fix? 😄

itsdouges avatar Jun 02 '20 02:06 itsdouges