Update README examples

This commit is contained in:
Tristan Edwards
2022-12-27 23:27:50 +01:00
parent e565a176e3
commit 4ec0ec2934

View File

@@ -20,12 +20,12 @@ import { NostrProvider } from "nostr-react";
const relayUrls = [
"wss://nostr-pub.wellorder.net",
"wss://nostr-relay.untethr.me",
"wss://relay.nostr.ch",
];
function MyApp() {
return (
<NostrProvider relayUrls={relayUrls} debug>
<NostrProvider relayUrls={relayUrls} debug={true}>
<App />
</NostrProvider>
);
@@ -40,20 +40,15 @@ You can now use the `useNostr` and `useNostrEvents` hooks in your components!
import { useNostrEvents, dateToUnix } from "nostr-react";
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: {
since: dateToUnix(now.current), // all new events from now
kinds: [1],
since: dateToUnix(new Date()), // all new events from now
},
});
useEffect(() => {
// Stop subscribing when component unmounts:
return () => {
unsubscribe();
};
}, []);
return (
<>
{events.map((event) => (
@@ -70,7 +65,7 @@ const GlobalFeed = () => {
import { useNostrEvents } from "nostr-react";
const ProfileFeed = () => {
const { events, unsubscribe } = useNostrEvents({
const { events } = useNostrEvents({
filter: {
authors: [
"9c2a6495b4e3de93f3e1cc254abe4078e17c64e5771abc676a5e205b62b1286c",
@@ -80,13 +75,6 @@ const ProfileFeed = () => {
},
});
useEffect(() => {
// Stop subscribing when component unmounts:
return () => {
unsubscribe();
};
}, []);
return (
<>
{events.map((event) => (