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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-facebook

v11.0.2

Published

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

Downloads

146,697

Readme

React Facebook

NPM version NPM downloads Documentation TypeScript License Bundle Size

Why react-facebook?

  • All-in-one — Login, Pixel tracking, Share, Like, Comments, Embedded Posts/Videos, Page plugin, Graph API
  • TypeScript-first — Every component, hook, and return type is fully typed
  • SSR & Next.js ready'use client' directives and window guards built in. No window is not defined errors
  • Modern React — Hooks API (useLogin, usePixel, useGraphAPI, useLocale, ...) and Context-based provider
  • Small footprint — Tree-shakeable, under 15 KB gzipped
  • Error resilientFacebookErrorBoundary gracefully handles ad blockers and network failures
  • GDPR compliant — Built-in consent management for Pixel tracking

Installation

npm install react-facebook

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>
  );
}

Documentation

seeden.github.io/react-facebook — Full docs with examples, API reference, and guides.

  • Getting Started — Installation, provider setup, first component
  • Components — Login, Like, Share, Comments, Embeds, Page
  • Hooks — useLogin, useGraphAPI, useShare, useLocale, and more
  • Facebook Pixel — Tracking, page views, custom events, GDPR consent
  • Guides — Facebook Login setup, Pixel setup, version upgrades

What's Included

Components

| Component | Description | | -------------------------------- | --------------------------------------------------------- | | FacebookProvider | SDK initialization and context provider | | Login | Facebook Login with render props and children as function | | Like | Like button with layout, color scheme, and share options | | Share / ShareButton | Share dialog and inline share button | | Comments / CommentsCount | Comments plugin and count display | | EmbeddedPost / EmbeddedVideo | Embed Facebook posts and videos | | Page | Facebook Page plugin with tabs | | FacebookPixelProvider | Standalone Pixel provider (no SDK required) | | FacebookErrorBoundary | Catches SDK failures with customizable fallback |

Hooks

| Hook | Description | | ---------------------------------- | ---------------------------------------------------- | | useLogin | Programmatic login and logout | | useProfile | Fetch user profile fields | | useLoginStatus | Check authentication status | | useGraphAPI | Typed Graph API calls with loading/error/data states | | useShare / useFeed / useSend | Share, Feed, and Send dialogs | | usePixel / usePageView | Pixel event tracking and automatic page views | | useLocale | Dynamic language switching without page reload | | useFacebook | Direct access to the Facebook SDK instance |

Examples

Facebook Pixel

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

function App() {
  return (
    <FacebookProvider appId="YOUR_APP_ID" pixelId="YOUR_PIXEL_ID">
      <TrackingExample />
    </FacebookProvider>
  );
}

function TrackingExample() {
  const { track, pageView, grantConsent, revokeConsent } = usePixel();

  return <button onClick={() => track('Purchase', { value: 29.99, currency: 'USD' })}>Buy Now</button>;
}

Or use the drop-in imperative API (no provider needed):

import { ReactPixel } from 'react-facebook';

ReactPixel.init('YOUR_PIXEL_ID');
ReactPixel.pageView();
ReactPixel.track('Purchase', { value: 29.99, currency: 'USD' });

Graph API

import { useGraphAPI } from 'react-facebook';

function UserProfile() {
  const { data, loading, error } = useGraphAPI({
    path: '/me',
    params: { fields: 'name,email,picture' },
  });

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

  return <p>Welcome, {(data as { name: string })?.name}</p>;
}

Login with Hooks

import { useLogin, useProfile } from 'react-facebook';

function AuthFlow() {
  const { login, logout, loading } = useLogin();
  const { profile } = useProfile(['name', 'email', 'picture']);

  if (profile) {
    return (
      <div>
        <p>Welcome, {profile.name}</p>
        <button onClick={() => logout()}>Logout</button>
      </div>
    );
  }

  return (
    <button onClick={() => login({ scope: 'email,public_profile' })} disabled={loading}>
      Continue with Facebook
    </button>
  );
}

Error Boundary

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

<FacebookProvider appId="YOUR_APP_ID">
  <FacebookErrorBoundary
    fallback={(error, reset) => (
      <div>
        <p>Facebook failed to load: {error.message}</p>
        <button onClick={reset}>Try again</button>
      </div>
    )}
  >
    <Login onSuccess={handleSuccess}>Login with Facebook</Login>
  </FacebookErrorBoundary>
</FacebookProvider>;

Dynamic Locale

import { useLocale } from 'react-facebook';

function LocaleSwitcher() {
  const { locale, setLocale, isChangingLocale } = useLocale();

  return (
    <select value={locale} onChange={(e) => setLocale(e.target.value)} disabled={isChangingLocale}>
      <option value="en_US">English</option>
      <option value="es_ES">Spanish</option>
      <option value="fr_FR">French</option>
      <option value="de_DE">German</option>
    </select>
  );
}

Support

If you find this project useful, please consider becoming a sponsor.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

MIT