add unsubscribe method to README

This commit is contained in:
Tristan Edwards 2022-12-25 18:56:15 +01:00
parent adc72d685f
commit 0009638292

View File

@ -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) => (