npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tribeplatform/react-sdk

v2.2.0

Published

> TODO: description

Downloads

119

Readme

Getting Started

What is Tribe React SDK?

Tribe React SDK allows developers to easily embed Tribe directly into their React apps. The SDK provides React hooks for accessing the data on the Tribe Platform and enables full customizability of the UI.

The state management, caching, optimistic response, etc. is all handled on the SDK level. This removes all the complexities in building an online community and lets the developer to focus on the look and feel so it fits their product or brand perfectly.

How to use Tribe React SDK?

1. Generate an access token

First you need to generate an access token for the logged in member or guest. You can generate it directly using our GraphQL API or JavaScript SDK.

2. Install the React SDK

You can simply install Tribe React SDK using the following npm command: With Yarn:

$ yarn add @tribeplatform/react-sdk

With NPM:

$ npm install @tribeplatform/react-sdk

3. Inject Tribe React provider

Wrap your App by TribeProvider. Here is how it will look like in a basic app created by create-react-app.

import { Provider as TribeProvider } from '@tribeplatform/react-sdk'

ReactDOM.render(
  <React.StrictMode>
    <TribeProvider
      config={{
        accessToken: '{yourAccessToken}',
        baseUrl: 'https://app.tribe.so/graphql',
      }}
    >
      <App />
    </TribeProvider>
  </React.StrictMode>,
  document.getElementById('root'),
)

You should replace {yourAccessToken} with the access token generated in step 1.

4. Use hooks to query data

Tribe React SDK uses react-query under the hood for making the queries and performing GraphQL mutations.

Here is an example for fetching and displaying your community's spaces using Tribe react hooks:

import { useSpaces } from '@tribeplatform/react-sdk/hooks'

export function SpaceList() {
  const { data: spaces, isLoading } = useSpaces({ fields: { image: 'basic' } })

  return (
    <ul>
      {isLoading && <div>Loading...</div>}
      {spaces?.pages[0]?.nodes?.map(space => (
        <li className="mb-3">{space.name}</li>
      ))}
    </ul>
  )

Here is a more complicated example on fetching feed posts with load more button:

import { useFeed } from '@tribeplatform/react-sdk/hooks'
import { simplifyPaginatedResult } from '@tribeplatform/react-sdk/utils'

export function Feed() {
  const {
    data: posts,
    isLoading,
    fetchNextPage,
    hasNextPage,
    isFetchingNextPage,
  } = useFeed({
    fields: {
      owner: { member: 'all' },
      reactions: { variables: { limit: 5 }, fields: 'basic' },
    },
    variables: { limit: 10 },
  })

  // Convert pages of notes into a flat list of nodes
  const { nodes: latestPosts } = simplifyPaginatedResult(posts)

  return (
    <main>
      {isLoading && <div>Loading...</div>}
      <ul>
        {latestPosts?.map(post => {
          return (
            <li>{post.title}</li>
          )
        })}
      </ul>
      {hasNextPage && (
        <button
          onClick={() => fetchNextPage()}
        >
          {isFetchingNextPage ? `Loading more...` : `Load more`}
        </button>
      )}      
    </main>
  )
}

The above example, displays a list of posts in the feed and a "Load more" button. Clicking on the "Load more" button automatically appends the new data to the list and the new posts are shown right away.

5. Use hooks to perform an action

Similar to queries, you can use Tribe React hooks to perform actions.

Here is an example of how performing Like action on a post can look like:

import {
  useAddReaction,
  useRemoveReaction,
} from '@tribeplatform/react-sdk/hooks'

export function LikeButton({ post }) {
  const { mutate: likePost } = useAddReaction()
  const { mutate: unlikePost } = useRemoveReaction()
  
  const reacted = !!post?.reactions?.find(reaction => {
    return reaction.reaction === '+1' && reaction.reacted
  })

  return (
    <button
      onClick={e => {
        if (reacted) unlikePost({ postId: post?.id, reaction: '+1' })
        else
          likePost({
            postId: post?.id,
            input: { reaction: '+1' },
          })
      }}
    >
      {reacted ? "Unlike" : "Like"}
    </button>
  )
}

Clicking on the "Like" button will change the value of the post right away, and the button will be switched to "Unlike" right away.