Skip to main content

Getting Started

What is Bettermode React SDK?

Bettermode React SDK allows developers to easily embed Bettermode directly into their React apps. The SDK provides React hooks for accessing the data on the Bettermode 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 Bettermode 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 Bettermode React SDK using the following npm command:

npm install @tribeplatform/react-sdk

3. Inject Bettermode React provider

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

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

accessToken: '{yourAccessToken}',
baseUrl: '',
<App />

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

4. Use hooks to query data

Bettermode 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 Bettermode 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">{}</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 Bettermode 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.