mirror of
https://github.com/t4t5/nostr-react.git
synced 2025-09-17 21:20:29 +02:00
Update README examples
This commit is contained in:
26
README.md
26
README.md
@@ -20,12 +20,12 @@ import { NostrProvider } from "nostr-react";
|
|||||||
|
|
||||||
const relayUrls = [
|
const relayUrls = [
|
||||||
"wss://nostr-pub.wellorder.net",
|
"wss://nostr-pub.wellorder.net",
|
||||||
"wss://nostr-relay.untethr.me",
|
"wss://relay.nostr.ch",
|
||||||
];
|
];
|
||||||
|
|
||||||
function MyApp() {
|
function MyApp() {
|
||||||
return (
|
return (
|
||||||
<NostrProvider relayUrls={relayUrls} debug>
|
<NostrProvider relayUrls={relayUrls} debug={true}>
|
||||||
<App />
|
<App />
|
||||||
</NostrProvider>
|
</NostrProvider>
|
||||||
);
|
);
|
||||||
@@ -40,20 +40,15 @@ 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 { events, unsubscribe } = useNostrEvents({
|
const now = useRef(new Date()); // Make sure current time isn't re-rendered
|
||||||
|
|
||||||
|
const { isLoading, connectedRelays, events } = useNostrEvents({
|
||||||
filter: {
|
filter: {
|
||||||
|
since: dateToUnix(now.current), // all new events from now
|
||||||
kinds: [1],
|
kinds: [1],
|
||||||
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) => (
|
||||||
@@ -70,7 +65,7 @@ const GlobalFeed = () => {
|
|||||||
import { useNostrEvents } from "nostr-react";
|
import { useNostrEvents } from "nostr-react";
|
||||||
|
|
||||||
const ProfileFeed = () => {
|
const ProfileFeed = () => {
|
||||||
const { events, unsubscribe } = useNostrEvents({
|
const { events } = useNostrEvents({
|
||||||
filter: {
|
filter: {
|
||||||
authors: [
|
authors: [
|
||||||
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
|
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
|
||||||
@@ -80,13 +75,6 @@ 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