mirror of https://github.com/waku-org/js-waku.git
Clean up observer when component dismount
This commit is contained in:
parent
1d3f0e4c8a
commit
4e7f75868f
|
@ -72,6 +72,11 @@ function App() {
|
|||
useEffect(() => {
|
||||
if (!waku) return;
|
||||
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
||||
|
||||
return function cleanUp() {
|
||||
if (!waku) return;
|
||||
waku.relay.deleteObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -81,6 +86,16 @@ function App() {
|
|||
observerDirectMessage.bind({}, ethDmKeyPair.privateKey),
|
||||
[DirectMessageContentTopic]
|
||||
);
|
||||
|
||||
return function cleanUp() {
|
||||
if (!waku) return;
|
||||
if (!ethDmKeyPair) return;
|
||||
waku.relay.deleteObserver(
|
||||
observerDirectMessage.bind({}, ethDmKeyPair.privateKey),
|
||||
[DirectMessageContentTopic]
|
||||
);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
const broadcastPublicKey = () => {
|
||||
|
@ -109,6 +124,8 @@ function App() {
|
|||
};
|
||||
|
||||
const sendDummyMessage = () => {
|
||||
if (!waku) return;
|
||||
|
||||
console.log(`Sending messages to ${publicKeys.size} peers`);
|
||||
publicKeys.forEach(async (publicKey, address) => {
|
||||
const msg = await encodeEncryptedWakuMessage(
|
||||
|
|
Loading…
Reference in New Issue