1.6.1 • Published 6 months ago

@snort/system-react v1.6.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

@snort/system-react

React hooks for @snort/system

Available hooks

useRequestBuilder(RequestBuilder)

The main hook which allows you to subscribe to nostr relays and returns a reactive store.

useUserProfile(pubkey: string | undefined)

Profile hook, profile loading is automated, this hook will return the profile from cache and also refresh the cache in the background (stale-while-revalidate)

useEventFeed(NostrLink) / useEventsFeed(Array<NostrLink>)

A simple hook which can load events using the NostrLink class, this class contains one NIP-19 entity nevent/naddr etc.

useReactions(id, Array<NostrLink>)

Loads reactions for a set of events, this can be a set of posts on a profile or an arbitary list of events.

useEventReactions(NostrLink, Array<NostrEvent>)

Process a set of related events (usually results from useReactions) and return likes/dislikes/reposts/zaps

useUserSearch()

Search for profiles in the profile cache, this also returns exact links if they match

useSystemState(System)

Hook state of the nostr system

Example:

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(sub);
  return (
    <>
      {data.map(a => (
        <Note ev={a} />
      ))}
    </>
  );
}

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

6 months ago

1.6.0

7 months ago

1.5.7

7 months ago

1.5.6

7 months ago

1.5.5

7 months ago

1.5.4

8 months ago

1.5.3

8 months ago

1.4.2

11 months ago

1.4.1

11 months ago

1.4.0

12 months ago

1.3.8

12 months ago

1.3.7

12 months ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.5.1

9 months ago

1.3.3

1 year ago

1.5.0

9 months ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.12

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.6

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.1

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago