neynarxyz / react

React SDK for Farcaster components - powered by Neynar APIs
https://neynar-react.vercel.app
MIT License
19 stars 14 forks source link
expo farcaster neynar react react-native signin-with-neynar

@neynar/react

Introduction

@neynar/react is the official Frontend SDK from Neynar. This SDK includes React components to build Farcaster clients.

You can also test the components out in our Storybook.

Installation

  1. Install the @neynar/react package using npm or yarn.

    For yarn:

    yarn add @neynar/react

    For npm:

    npm install @neynar/react
  2. Make sure that the following peer dependencies are installed.

    {
    "hls.js": "^1.5.13",
    "@pigment-css/react": "^0.0.9",
    "react": "^18.3.0",
    "react-dom": "^18.3.0",
    "swr": "^2.2.5"
    }

    or if you want to install them all at once:

    For yarn:

    yarn add react react-dom @pigment-css/react hls.js swr

    For npm:

    npm install react react-dom @pigment-css/react hls.js swr
  3. Import the following CSS file in your project's root file (e.g., layout.tsx for a Next.js app).

    import "@neynar/react/dist/style.css";

Components

Note: If you are using <NeynarAuthButton /> or if you're using <NeynarCastCard /> with allowReactions enabled (using Neynar reactions), please set your authorized origin to your local (localhost:6006 for Storybook) and production environments at dev.neynar.com.

<NeynarAuthButton />

This component lets you embed a Sign In With Neynar button in your app, which you can use for read-only or read + write access to the user's Farcaster account.

Params:

Usage:

import { NeynarAuthButton } from "@neynar/react";

<NeynarAuthButton 
  primary={true} 
  label="Sign In with Neynar" 
/>

<NeynarProfileCard />

This component displays a user's Farcaster profile information.

Params:

Usage:

import { NeynarProfileCard } from "@neynar/react";

<NeynarProfileCard 
  fid={1} 
  viewerFid={1} 
/>

<NeynarCastCard />

This component displays a specific cast (post) on Farcaster.

Params:

Usage:

import { NeynarCastCard } from "@neynar/react";

<NeynarCastCard 
  type="url" 
  identifier="https://warpcast.com/dylsteck.eth/0xda6b1699" 
  viewerFid={1}  
/>

<NeynarFeedList />

This component displays a list of casts (posts) on Farcaster.

Params:

Usage:

import { NeynarFeedList } from "@neynar/react";

<NeynarFeedList 
  feedType="filter" 
  filterType="fids" 
  fids="2"
  viewerFid={2} 
/>

<NeynarConversationList />

This component displays a conversation (thread) of casts (posts) on Farcaster.

Params:

Usage:

import { NeynarConversationList } from "@neynar/react";

<NeynarConversationList 
  type="url" 
  identifier="https://warpcast.com/dwr.eth/0x1b0792bc" 
  replyDepth={2}
  limit={50}
  viewerFid={1}  
/>

<NeynarFrameCard />

This component displays a specific frame on Farcaster.

Params:

Usage:

import { NeynarFrameCard } from "@neynar/react";

<NeynarFrameCard 
  url="https://events.xyz/events/a010d617"
/>

How to securely implement write actions

There are currently two components that offer props for develoeprs to handle write actions: NeynarCastCard(write action handlers for cast reactions) and NeynarFeedCard(write action handlers for frame interactions). We highly recommend that you call Neynar's POST APIs(or other intended APIs) from your own, authenticated server to ensure that your Neynar API key credentials are not exposed on the client-side. Check out the example app below for a guide and example of securely implementing write actions.

Example app

Check out our example app for a demonstration of how to use @neynar/react.