snort/packages/system-react
Kieran e65845af6d
continuous-integration/drone/push Build is failing Details
feat: include targetEvents in parsedZap
2023-11-14 13:55:15 +00:00
..
example Formatting / Intl 2023-08-24 16:55:36 +01:00
src refactor: simplify useEventReactions hook 2023-11-14 12:55:46 +00:00
README.md Update system-react 2023-09-15 12:48:55 +01:00
package.json feat: include targetEvents in parsedZap 2023-11-14 13:55:15 +00:00
tsconfig.json Fix tests 2023-10-06 13:16:28 +01:00

README.md

@snort/system-react

React hooks for @snort/system

Sample:

import { useMemo } from "react";
import { SnortContext, useRequestBuilder, useUserProfile } from "@snort/system-react";
import { NostrSystem, NoteCollection, RequestBuilder, TaggedNostrEvent } from "@snort/system";

const System = new NostrSystem({});

// some bootstrap relays
["wss://relay.snort.social", "wss://nos.lol"].forEach(r => System.ConnectToRelay(r, { read: true, write: false }));

export function Note({ ev }: { ev: TaggedNostrEvent }) {
  const profile = useUserProfile(ev.pubkey);

  return (
    <div>
      Post by: {profile.name ?? profile.display_name}
      <p>{ev.content}</p>
    </div>
  );
}

export function UserPosts(props: { pubkey: string }) {
  const sub = useMemo(() => {
    const rb = new RequestBuilder("get-posts");
    rb.withFilter().authors([props.pubkey]).kinds([1]).limit(10);

    return rb;
  }, [props.pubkey]);

  const data = useRequestBuilder(NoteCollection, sub);
  return (
    <>
      {data.data.map(a => (
        <Note ev={a} />
      ))}
    </>
  );
}

export function MyApp() {
  return (
    <SnortContext.Provider value={System}>
      <UserPosts pubkey="63fe6318dc58583cfe16810f86dd09e18bfd76aabc24a0081ce2856f330504ed" />
    </SnortContext.Provider>
  );
}