TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

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'

        accessToken: '{yourAccessToken}',
        baseUrl: 'https://app.tribe.so/graphql',
      <App />

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 (
      {isLoading && <div>Loading...</div>}
      {spaces?.pages[0]?.nodes?.map(space => (
        <li className="mb-3">{space.name}</li>

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,
  } = 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 (
      {isLoading && <div>Loading...</div>}
        {latestPosts?.map(post => {
          return (
      {hasNextPage && (
          onClick={() => fetchNextPage()}
          {isFetchingNextPage ? `Loading more...` : `Load more`}

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 {
} 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 (
      onClick={e => {
        if (reacted) unlikePost({ postId: post?.id, reaction: '+1' })
            postId: post?.id,
            input: { reaction: '+1' },
      {reacted ? "Unlike" : "Like"}

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




Package Sidebar


npm i @tribeplatform/react-sdk

Weekly Downloads






Unpacked Size

2.61 MB

Total Files


Last publish


  • amirtribe
  • farazfarajitribe2
  • me.moozeh
  • farzadsh
  • zeer01
  • amirrezaamirfatahi
  • keyvan-tribe
  • syavash
  • ermiaqasemi
  • firiz-tribe
  • farnood
  • sergei.kartin