Skip to content

Commit

Permalink
useSubscribe initial state, faster feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed Aug 23, 2023
1 parent 602587d commit 0aab992
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/js/nostr/hooks/useSubscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ const useSubscribe = (ops: SubscribeOptions) => {
mergeSubscriptions = defaultOps.mergeSubscriptions,
} = ops;

const [events, setEvents] = useState<Event[]>([]);
const lastUntilRef = useRef<number | null>(null);

const updateEvents = useCallback(() => {
const getEvents = useCallback(() => {
// maybe we should still add filter by displaycount?
let e = EventDB.findArray({ ...filter, limit: undefined });
if (filterFn) {
e = e.filter(filterFn);
}
setEvents(e);
return e;
}, [filter, filterFn]);

const [events, setEvents] = useState<Event[]>(getEvents());
const lastUntilRef = useRef<number | null>(null);

const updateEvents = useCallback(() => {
setEvents(getEvents());
}, [getEvents]);

useEffect(() => {
setEvents([]);
if (!enabled || !filter) return;
Expand Down

0 comments on commit 0aab992

Please sign in to comment.