Skip to content

Commit 0009638

Browse files
committed
add unsubscribe method to README
1 parent adc72d6 commit 0009638

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ You can now use the `useNostr` and `useNostrEvents` hooks in your components!
4040
import { useNostrEvents, dateToUnix } from "nostr-react";
4141

4242
const GlobalFeed = () => {
43-
const { isLoading, events } = useNostrEvents({
43+
const { events, unsubscribe } = useNostrEvents({
4444
filter: {
4545
kinds: [1],
4646
since: dateToUnix(new Date()), // all new events from now
4747
},
4848
});
4949

50+
useEffect(() => {
51+
// Stop subscribing when component unmounts:
52+
return () => {
53+
unsubscribe();
54+
};
55+
}, []);
56+
5057
return (
5158
<>
5259
{events.map((event) => (
@@ -63,7 +70,7 @@ const GlobalFeed = () => {
6370
import { useNostrEvents } from "nostr-react";
6471

6572
const ProfileFeed = () => {
66-
const { events } = useNostrEvents({
73+
const { events, unsubscribe } = useNostrEvents({
6774
filter: {
6875
authors: [
6976
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
@@ -73,6 +80,13 @@ const ProfileFeed = () => {
7380
},
7481
});
7582

83+
useEffect(() => {
84+
// Stop subscribing when component unmounts:
85+
return () => {
86+
unsubscribe();
87+
};
88+
}, []);
89+
7690
return (
7791
<>
7892
{events.map((event) => (

0 commit comments

Comments
 (0)