diff --git a/README.md b/README.md index 4bc6752..a6c4eef 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,20 @@ You can now use the `useNostr` and `useNostrEvents` hooks in your components! import { useNostrEvents, dateToUnix } from "nostr-react"; const GlobalFeed = () => { - const { isLoading, events } = useNostrEvents({ + const { events, unsubscribe } = useNostrEvents({ filter: { kinds: [1], since: dateToUnix(new Date()), // all new events from now }, }); + useEffect(() => { + // Stop subscribing when component unmounts: + return () => { + unsubscribe(); + }; + }, []); + return ( <> {events.map((event) => ( @@ -63,7 +70,7 @@ const GlobalFeed = () => { import { useNostrEvents } from "nostr-react"; const ProfileFeed = () => { - const { events } = useNostrEvents({ + const { events, unsubscribe } = useNostrEvents({ filter: { authors: [ "9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c", @@ -73,6 +80,13 @@ const ProfileFeed = () => { }, }); + useEffect(() => { + // Stop subscribing when component unmounts: + return () => { + unsubscribe(); + }; + }, []); + return ( <> {events.map((event) => (