mirror of
https://github.com/t4t5/nostr-react.git
synced 2025-09-17 00:36:09 +02:00
add unsubscribe method to README
This commit is contained in:
18
README.md
18
README.md
@@ -40,13 +40,20 @@ You can now use the `useNostr` and `useNostrEvents` hooks in your components!
|
|||||||
import { useNostrEvents, dateToUnix } from "nostr-react";
|
import { useNostrEvents, dateToUnix } from "nostr-react";
|
||||||
|
|
||||||
const GlobalFeed = () => {
|
const GlobalFeed = () => {
|
||||||
const { isLoading, events } = useNostrEvents({
|
const { events, unsubscribe } = useNostrEvents({
|
||||||
filter: {
|
filter: {
|
||||||
kinds: [1],
|
kinds: [1],
|
||||||
since: dateToUnix(new Date()), // all new events from now
|
since: dateToUnix(new Date()), // all new events from now
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Stop subscribing when component unmounts:
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{events.map((event) => (
|
{events.map((event) => (
|
||||||
@@ -63,7 +70,7 @@ const GlobalFeed = () => {
|
|||||||
import { useNostrEvents } from "nostr-react";
|
import { useNostrEvents } from "nostr-react";
|
||||||
|
|
||||||
const ProfileFeed = () => {
|
const ProfileFeed = () => {
|
||||||
const { events } = useNostrEvents({
|
const { events, unsubscribe } = useNostrEvents({
|
||||||
filter: {
|
filter: {
|
||||||
authors: [
|
authors: [
|
||||||
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
|
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
|
||||||
@@ -73,6 +80,13 @@ const ProfileFeed = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Stop subscribing when component unmounts:
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{events.map((event) => (
|
{events.map((event) => (
|
||||||
|
Reference in New Issue
Block a user