mirror of
https://github.com/logos-messaging/waku-react.git
synced 2026-01-02 22:23:11 +00:00
accept undefined node, handle empty message case
This commit is contained in:
parent
bfaaf2c21e
commit
c536d9abda
@ -1,14 +1,14 @@
|
||||
import React from "react";
|
||||
import type { IDecodedMessage, IDecoder, IFilter } from "@waku/interfaces";
|
||||
import type { IDecodedMessage, IDecoder, IFilter, Waku } from "@waku/interfaces";
|
||||
|
||||
import type { HookState } from "./types";
|
||||
|
||||
type AbstractFilterNode = {
|
||||
type AbstractFilterNode = Waku & {
|
||||
filter: IFilter;
|
||||
};
|
||||
|
||||
type UseFilterMessagesParams = {
|
||||
node: AbstractFilterNode;
|
||||
node: undefined | AbstractFilterNode;
|
||||
decoder: IDecoder<IDecodedMessage>;
|
||||
};
|
||||
|
||||
@ -27,12 +27,20 @@ export const useFilterMessages = (
|
||||
|
||||
const pushMessage = React.useCallback(
|
||||
(message: IDecodedMessage): void => {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
setMessage((prev) => [...prev, message]);
|
||||
},
|
||||
[setMessage],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
let unsubscribe: null | (() => Promise<void>) = null;
|
||||
setLoading(true);
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ import React from "react";
|
||||
import type {
|
||||
IDecodedMessage,
|
||||
IDecoder,
|
||||
Waku,
|
||||
IStore,
|
||||
StoreQueryOptions,
|
||||
Waku,
|
||||
} from "@waku/interfaces";
|
||||
|
||||
import type { HookState } from "./types";
|
||||
@ -14,7 +14,7 @@ type AbstractStoreNode = Waku & {
|
||||
};
|
||||
|
||||
type UseStoreMessagesParams = {
|
||||
node: AbstractStoreNode;
|
||||
node: undefined | AbstractStoreNode;
|
||||
decoder: IDecoder<IDecodedMessage>;
|
||||
options: StoreQueryOptions;
|
||||
};
|
||||
@ -44,6 +44,10 @@ export const useStoreMessages = (
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user