Open Source
The Facebook SDK for React
Login, Pixel, Share, Like, Comments, Graph API. One package. Fully typed. SSR-safe. Works with Next.js out of the box.
useLogin+<Login />PixelusePixelGraph APIuseGraphAPIShareuseShare+<Share />Like<Like />Comments<Comments />Embedded Posts<EmbeddedPost />Embedded Videos<EmbeddedVideo />Error Boundary<FacebookErrorBoundary />The API
Four hooks. Four patterns.
Login
import { useLogin } from 'react-facebook';
function LoginButton() {
const { login, loading, error } = useLogin();
async function handleLogin() {
const res = await login({
scope: 'public_profile,email',
});
console.log(res);
}
return (
<button onClick={handleLogin} disabled={loading}>
{loading ? 'Logging in...' : 'Login with Facebook'}
</button>
);
}Pixel Tracking
import { usePixel } from 'react-facebook';
function Checkout() {
const { track, grantConsent } = usePixel();
return (
<>
<button onClick={() => grantConsent()}>
Accept Cookies
</button>
<button onClick={() => track('Purchase', {
value: 49.99, currency: 'USD',
})}>
Complete Order
</button>
</>
);
}Share
import { useShare } from 'react-facebook';
function ShareButton() {
const { share } = useShare();
async function handleShare() {
await share({
href: 'https://your-site.com',
hashtag: '#reactfacebook',
});
}
return (
<button onClick={handleShare}>
Share this page
</button>
);
}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.message}</p>;
return <p>Welcome, {data?.name}</p>;
}Live
Real widgets. Real SDK.
These are actual Facebook widgets rendered by react-facebook on this page. No screenshots, no mocks.
Embedded Video
Share Button
Page Plugin
Embedded Post
Next.js
Works with App Router
Wrap your layout with FacebookProvider. Use components and hooks anywhere. SSR-safe with built-in 'use client' directives.
// app/layout.tsx
import { FacebookProvider } from 'react-facebook';
export default function RootLayout({ children }) {
return (
<html>
<body>
<FacebookProvider appId="YOUR_APP_ID" language="en_US">
{children}
</FacebookProvider>
</body>
</html>
);
}
// app/page.tsx
import {
Login, Like, Share, Comments,
EmbeddedPost, EmbeddedVideo, Page,
} from 'react-facebook';
export default function Home() {
return (
<>
<Login scope="public_profile,email" onSuccess={console.log}>
Login with Facebook
</Login>
<Like href="https://your-site.com" />
<Share href="https://your-site.com" />
<Comments href="https://your-site.com/post" />
<EmbeddedPost href="https://facebook.com/Meta/posts/123" width={500} />
<EmbeddedVideo href="https://facebook.com/Meta/videos/123" width={500} />
<Page href="https://facebook.com/meta" tabs="timeline" />
</>
);
}Community
Built with react-facebook
Companies and developers shipping with react-facebook in production. Get your logo and a dofollow backlink on this page.
Using react-facebook in production? Get your company featured here. We add your logo with a dofollow backlink, visible to every developer who visits.
Your logo on this page
Visible to every developer who visits
Dofollow backlink
Direct SEO value to your domain
Community recognition
Show you build with modern tools
Your company could be here