API Reference

Complete reference for all components, hooks, and types

Components

FacebookProvider

Root provider component that initializes Facebook SDK

Props

NameTypeRequiredDescription
appIdstringYesYour Facebook App ID
versionstringv18.0Facebook SDK version
languagestringen_USLocale for SDK
debugbooleanfalseEnable debug mode
xfbmlbooleantrueParse XFBML tags
cookiebooleantrueEnable cookies
lazybooleanfalseLazy load SDK
pixelPixelOptionsNoFacebook Pixel configuration
Example
<FacebookProvider
appId="123456789"
version="v18.0"
language="en_US"
pixel={{ pixelId: "987654321" }}
>
{children}
</FacebookProvider>

Login

Modern unified Facebook login component (replaces LoginButton and FacebookLogin)

Props

NameTypeRequiredDescription
scopestring[]['public_profile', 'email']Array of permissions
fieldsstring[][]Profile fields to fetch
onSuccess(response) => voidNoSuccess callback
onError(error) => voidNoError callback
onProfileSuccess(profile) => voidNoProfile success callback
childrenReactNode | FunctionNoContent or render function
asElementType | ComponentTypebuttonComponent to render as
disabledbooleanfalseDisable login
classNamestringNoCSS class name
returnScopesbooleanfalseReturn granted scopes
authTypestring[]NoAuth type parameters
rerequestbooleanfalseRe-request permissions
reauthorizebooleanfalseRe-authorize permissions
Example
// Basic usage with Tailwind
<Login
scope={['email', 'public_profile']}
onSuccess={(response) => console.log('Success:', response)}
onError={(error) => console.error('Error:', error)}
className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700"
>
Continue with Facebook
</Login>
// Children as function pattern
<Login
scope={['public_profile', 'email']}
fields={['name', 'email', 'picture']}
onSuccess={handleSuccess}
onProfileSuccess={(profile) => console.log('Profile:', profile)}
>
{({ onClick, isLoading, isDisabled }) => (
<button
onClick={onClick}
disabled={isDisabled}
className={`btn ${isLoading ? 'loading' : ''}`}
>
{isLoading ? 'Connecting...' : 'Login with Facebook'}
</button>
)}
</Login>
// Custom element
<Login
as="a"
href="#"
className="text-blue-600 hover:underline"
>
Connect Facebook Account
</Login>

Share

Share dialog component

Props

NameTypeRequiredDescription
hrefstringYesURL to share
hashtagstringNoHashtag for the post
quotestringNoQuote to include
onSuccess() => voidNoSuccess callback
onError(error) => voidNoError callback
childrenRenderPropYesRender function
Example
<Share href="https://example.com">
{({ handleClick }) => (
<button onClick={handleClick}>Share</button>
)}
</Share>

Like

Facebook like button

⚠️ EU/EEA/UK users will not see this component unless logged into Facebook and have consented to cookies.

Props

NameTypeRequiredDescription
hrefstringYesURL to like
layoutLikeLayoutstandardButton layout style
size"small" | "large"smallButton size
showFacesbooleanfalseShow profile photos
sharebooleanfalseInclude share button
colorScheme"light" | "dark"lightColor scheme
Example
<Like
href="https://example.com"
layout="button_count"
size="large"
showFaces={true}
share={true}
/>

Comments

Embedded Facebook comments

EU/EEA/UK users must be logged into Facebook AND have consented to cookies. Component will not be visible otherwise.

Props

NameTypeRequiredDescription
hrefstringYesURL for comments
numPostsnumber10Number of posts to show
orderBy"social" | "reverse_time" | "time"socialSort order
widthstring | number550Plugin width
colorScheme"light" | "dark"lightColor scheme
Example
<Comments
href="https://example.com/article"
numPosts={20}
orderBy="social"
/>

Page

Embed a Facebook page in your website

Props

NameTypeRequiredDescription
hrefstringYesFacebook page URL
tabsstringtimelineComma-separated list of tabs
widthnumber340Plugin width
heightnumber500Plugin height
smallHeaderbooleanfalseUse small header
hideCoverbooleanfalseHide cover photo
showFacepilebooleantrueShow friends faces
Example
<Page
href="https://www.facebook.com/YourPage"
tabs="timeline,events,messages"
width={500}
height={600}
/>

EmbeddedPost

Embed a Facebook post in your website

Props

NameTypeRequiredDescription
hrefstringYesFacebook post URL
widthnumber500Plugin width
showTextbooleantrueShow post text
Example
<EmbeddedPost
href="https://www.facebook.com/user/posts/123456789"
width={500}
showText={true}
/>

EmbeddedVideo

Embed a Facebook video in your website

Props

NameTypeRequiredDescription
hrefstringYesFacebook video URL
widthnumber500Plugin width
showTextbooleantrueShow video description
allowFullScreenbooleantrueAllow fullscreen
Example
<EmbeddedVideo
href="https://www.facebook.com/facebook/videos/123456789"
width={500}
showText={true}
/>

CommentsCount

Display the number of comments for any URL

Props

NameTypeRequiredDescription
hrefstringYesURL to count comments for
Example
<CommentsCount href="https://example.com/article" />

ShareButton

Alternative share button implementation

Props

NameTypeRequiredDescription
hrefstringYesURL to share
layoutstringbuttonButton layout
size"small" | "large"smallButton size
childrenReactNodeNoButton content
Example
<ShareButton href="https://example.com">
Share this content
</ShareButton>

FacebookPixelProvider

Standalone Facebook Pixel provider (can be used independently)

Props

NameTypeRequiredDescription
pixelIdstringYesFacebook Pixel ID
autoConfigbooleantrueEnable automatic configuration
debugbooleanfalseEnable debug logging
advancedMatchingRecord<string, any>NoAdvanced matching parameters
lazybooleanfalseDelay initialization
childrenReactNodeYesChild components
Example
<FacebookPixelProvider
pixelId="123456789"
autoConfig={true}
debug={true}
advancedMatching={{
em: 'user@example.com', // hashed email
ph: '+1234567890' // hashed phone
}}
>
{children}
</FacebookPixelProvider>

Hooks

useFacebook

Access Facebook SDK instance and state

Returns

isLoading
boolean- SDK loading state
error
Error | undefined- Loading error if any
init
() => Promise<void>- Initialize SDK manually
api
Facebook | undefined- Facebook SDK instance
parse
(element) => Promise<void>- Parse XFBML elements
Example
const { isLoading, error, api } = useFacebook();
useEffect(() => {
if (api) {
api.getLoginStatus((response) => {
console.log(response);
});
}
}, [api]);

useLogin

Facebook login functionality

Returns

login
(options?) => Promise<LoginResponse>- Login function
logout
() => Promise<void>- Logout function
isLoading
boolean- Loading state
error
Error | undefined- Error state
Example
const { login, logout, isLoading } = useLogin();
const handleLogin = async () => {
const response = await login({
scope: 'email,public_profile'
});
console.log(response);
};

useProfile

Fetch user profile data

Returns

profile
UserProfile | null- User profile data
loading
boolean- Loading state
error
Error | undefined- Error state
fetchProfile
() => Promise<void>- Refetch profile
Example
const { profile, loading, fetchProfile } = useProfile();
if (profile) {
console.log(profile.name, profile.email);
}

usePixel

Facebook Pixel tracking with comprehensive event support

Returns

isLoading
boolean- Pixel initialization state
error
Error | undefined- Loading error if any
init
() => Promise<void>- Initialize pixel manually
pixel
FacebookPixel | undefined- Pixel instance
pageView
() => void- Track page view event
track
(event: PixelEventName, data?: object) => void- Track standard Facebook event
trackCustom
(eventName: string, data?: object) => void- Track custom event
grantConsent
() => void- Grant GDPR tracking consent
revokeConsent
() => void- Revoke GDPR tracking consent
fbq
(...args: any[]) => void- Direct access to fbq function
Example
const { track, trackCustom, pageView, grantConsent } = usePixel();
// Track standard Facebook events
track('Purchase', {
value: 25.00,
currency: 'USD',
contents: [{ id: 'product-123', quantity: 1 }]
});
track('ViewContent', {
content_ids: ['product-123'],
content_type: 'product',
value: 25.00,
currency: 'USD'
});
// Track custom events
trackCustom('NewsletterSignup', {
email_domain: 'gmail.com'
});
// GDPR compliance
grantConsent();
// Manual page view tracking
pageView();

usePageView

Automatic page view tracking with route change support

Returns

pageView
() => void- Manual page view trigger
isLoading
boolean- Loading state
Example
// Auto-track on mount
usePageView();
// Custom configuration
usePageView({
trackOnMount: true,
trackOnRouteChange: true,
data: { custom_param: 'value' }
});
// Manual tracking only
const { pageView } = usePageView({ trackOnMount: false });
pageView(); // Trigger manually

useLocale

Dynamic locale management

Returns

locale
string- Current locale
setLocale
(locale: string) => Promise<void>- Change locale
Example
const { locale, setLocale } = useLocale();
await setLocale('es_ES');

useShare

Share dialog functionality

Returns

share
(options) => Promise<void>- Open share dialog
isLoading
boolean- Loading state
error
Error | undefined- Error state
Example
const { share } = useShare();
await share({
href: 'https://example.com',
hashtag: '#react'
});

TypeScript Types

FacebookOptions

Configuration options for Facebook SDK

interface FacebookOptions {
appId: string;
version?: string;
language?: string;
debug?: boolean;
xfbml?: boolean;
cookie?: boolean;
lazy?: boolean;
}

PixelOptions

Facebook Pixel configuration

interface PixelOptions {
pixelId: string;
autoConfig?: boolean;
debug?: boolean;
advancedMatching?: Record<string, any>;
}

PixelEventName

Standard Facebook Pixel event names

type PixelEventName =
| 'PageView'
| 'ViewContent'
| 'Search'
| 'AddToCart'
| 'AddToWishlist'
| 'InitiateCheckout'
| 'AddPaymentInfo'
| 'Purchase'
| 'Lead'
| 'CompleteRegistration'
| 'Contact'
| 'CustomizeProduct'
| 'Donate'
| 'FindLocation'
| 'Schedule'
| 'StartTrial'
| 'SubmitApplication'
| 'Subscribe';

PixelEventData

Event data for Facebook Pixel tracking

interface PixelEventData {
// Standard parameters
value?: number;
currency?: string;
content_name?: string;
content_category?: string;
content_ids?: string[];
content_type?: string;
contents?: Array<{
id: string;
quantity?: number;
item_price?: number;
}>;
// E-commerce specific
num_items?: number;
search_string?: string;
status?: string;
// Custom parameters
[key: string]: any;
}

LoginResponse

Facebook login response

interface LoginResponse {
authResponse?: {
accessToken: string;
userID: string;
expiresIn: number;
signedRequest: string;
};
status: 'connected' | 'not_authorized' | 'unknown';
}

FacebookPixelContextInterface

Context interface for Facebook Pixel provider

interface FacebookPixelContextInterface {
isLoading: boolean;
error: Error | undefined;
init: () => Promise<void>;
pixel: FacebookPixel | undefined;
pageView: () => void;
track: (eventName: PixelEventName, data?: PixelEventData) => void;
trackCustom: (eventName: string, data?: PixelEventData) => void;
grantConsent: () => void;
revokeConsent: () => void;
fbq: (...args: any[]) => void;
}