mirror of
https://github.com/t4t5/nostr-react.git
synced 2025-03-17 13:31:43 +01:00
add unsubscribe method to README
This commit is contained in:
parent
adc72d685f
commit
0009638292
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";
|
||||
|
||||
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) => (
|
||||
|
Loading…
x
Reference in New Issue
Block a user