From f6aa75871228fee41b2e32d51e02330ab6dda391 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 3 Sep 2021 17:04:25 +1000 Subject: [PATCH] Small cleanup --- examples/store-reactjs-chat/src/App.js | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/store-reactjs-chat/src/App.js b/examples/store-reactjs-chat/src/App.js index 0143015d44..0826446397 100644 --- a/examples/store-reactjs-chat/src/App.js +++ b/examples/store-reactjs-chat/src/App.js @@ -32,13 +32,24 @@ function App() { React.useEffect(() => { if (!waku) return; - if (wakuStatus !== 'Connected to Store') return; + + // We do not handle disconnection/re-connection in this example + if (wakuStatus === 'Connected') return; + + waku.waitForConnectedPeer().then(() => { + // We are now connected to a store node + setWakuStatus('Connected'); + }); + }, [waku, wakuStatus]); + + React.useEffect(() => { + if (!waku) return; + if (wakuStatus !== 'Connected') return; const interval = setInterval(() => { waku.store .queryHistory([ContentTopic]) .catch((e) => { - // We may not be connected to a store node just yet console.log('Failed to retrieve messages', e); }) .then((retrievedMessages) => { @@ -51,18 +62,6 @@ function App() { return () => clearInterval(interval); }, [waku, wakuStatus]); - React.useEffect(() => { - if (!waku) return; - - // We do not handle disconnection/re-connection in this example - if (wakuStatus === 'Connected to Store') return; - - waku.waitForConnectedPeer().then(() => { - // We are now connected to a store node - setWakuStatus('Connected to Store'); - }); - }, [waku, wakuStatus]); - return (