React Facebook

React Facebook

The Facebook SDK for React. One package for Login, Pixel tracking, Share, Like, Comments, Graph API, and more. TypeScript-first, SSR-safe, works with Next.js.

React Facebook

The complete Facebook SDK for React — one package for everything.

Why react-facebook?

Facebook integration in React has been fragmented across abandoned, single-purpose packages with no TypeScript, no SSR support, and no maintenance. react-facebook is a unified, actively maintained solution that covers the entire Facebook platform.

Featurereact-facebook
Login & Logout<Login>, useLogin
Pixel TrackingusePixel, usePageView, ReactPixel
Graph APIuseGraphAPI with typed responses
Social PluginsLike, Share, Comments, Page, Embeds
TypeScriptFull type coverage, no @types/ needed
SSR / Next.js'use client' directives, window guards
Error HandlingFacebookErrorBoundary for ad blockers
GDPR ConsentBuilt-in grantConsent / revokeConsent
Bundle SizeTree-shakeable, under 15 KB gzipped
i18nDynamic locale switching with useLocale

Quick Start

import { FacebookProvider, Login } from 'react-facebook';

function App() {
  return (
    <FacebookProvider appId="YOUR_APP_ID">
      <Login
        onSuccess={(response) => console.log('Login success:', response)}
        onError={(error) => console.error('Login failed:', error)}
      >
        Login with Facebook
      </Login>
    </FacebookProvider>
  );
}

TypeScript First

Every hook and component is fully typed. Import the types you need:

import type { LoginResponse, AuthResponse, UseGraphAPIReturn } from 'react-facebook';
import { useGraphAPI } from 'react-facebook';

interface Photo {
  id: string;
  source: string;
  name: string;
}

function PhotoGallery() {
  const { data, loading, error } = useGraphAPI<{ data: Photo[] }>({
    path: '/me/photos',
    params: { fields: 'id,source,name', limit: 10 },
    autoFetch: true,
  });

  if (loading) return <p>Loading photos...</p>;
  if (error) return <p>Error: {error.message}</p>;

  return (
    <div className="grid grid-cols-3 gap-4">
      {data?.data.map((photo) => (
        <img key={photo.id} src={photo.source} alt={photo.name} />
      ))}
    </div>
  );
}

Try it live

See every component in action with interactive controls. Change props, switch languages, and preview results instantly in the Playground.

Explore

On this page