Installations
npm install react-facebook
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 6.0.0
Node Version
18.11.0
NPM Version
8.19.2
Score
92.6
Supply Chain
98.8
Quality
76.1
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (94.17%)
JavaScript (5.26%)
HTML (0.57%)
Developer
seeden
Download Statistics
Total Downloads
7,648,877
Last Day
615
Last Week
20,438
Last Month
96,728
Last Year
1,262,241
GitHub Statistics
792 Stars
254 Commits
144 Forks
22 Watching
1 Branches
27 Contributors
Bundle Size
23.85 kB
Minified
6.68 kB
Minified + Gzipped
Package Meta Information
Latest Version
9.0.12
Package Id
react-facebook@9.0.12
Unpacked Size
228.86 kB
Size
58.05 kB
File Count
140
NPM Version
8.19.2
Node Version
18.11.0
Total Downloads
Cumulative downloads
Total Downloads
7,648,877
Last day
-0.3%
615
Compared to previous day
Last week
6.5%
20,438
Compared to previous week
Last month
-15.9%
96,728
Compared to previous month
Last year
31.4%
1,262,241
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
Dev Dependencies
19
React Facebook Components
Components
- Facebook provider (provide settings to child components)
- Login button (provide user profile and signed request)
- Like button
- Share and Share button
- Comments
- Comments count
- Embedded post
- Embedded video
- Page
- Feed
- Group
- Message Us
- Customer Chat
- Save
- Status
- Share
- Subscribe
- User Profile
Support
Become my sponsor and help me maintain this project. Thank you
Initialisation
By default FacebookProvider is loading facebook script immediately after render (you are able to use it with SSR). If you want to download facebook script only when facebook component is rendered you need to add parameter lazy to FacebookProvider. Use only one instance of the FacebookProvider on your page.
Usage
Like button
1import { FacebookProvider, Like } from 'react-facebook'; 2 3export default function LikeExample() { 4 return ( 5 <FacebookProvider appId="123456789"> 6 <Like href="http://www.facebook.com" colorScheme="dark" showFaces share /> 7 </FacebookProvider> 8 ); 9}
useShare
1import { FacebookProvider, useShare } from 'react-facebook'; 2 3export default function ShareExample() { 4 const { share, isLoading, error } = useShare(); 5 6 async function handleShare() { 7 await share({ 8 href: 'http://www.facebook.com', 9 }); 10 } 11 12 return ( 13 <button type="button" disabled={isLoading} onClick={handleShare}>Share</button> 14 ); 15}
Share button
You can use predefined button
1import { FacebookProvider, ShareButton } from 'react-facebook'; 2 3export default function ShareButtonExample() { 4 return ( 5 <FacebookProvider appId="123456789"> 6 <ShareButton href="http://www.facebook.com" className="my-classname"> 7 Share 8 </ShareButton> 9 </FacebookProvider> 10 ); 11}
Comments
1import { FacebookProvider, Comments } from 'react-facebook'; 2 3export default function CommentsExample() { 4 return ( 5 <FacebookProvider appId="123456789"> 6 <Comments href="http://www.facebook.com" /> 7 </FacebookProvider> 8 ); 9}
If comments do not work and you are seeing this error in the browser console:
Refused to display 'https://www.facebook.com/v3.1/plugins/comments.php?blahblahblah' in a frame because it set 'X-Frame-Options' to 'DENY'.
Possible reasons:
- If the site visitor is from the EU region, the visitor needs to be both:
- Logged in to Facebook.
- Have third-party cookies enabled in FB privacy settings.
- User is using a browser that is blocking third party cookies by default (for example Safari and Firefox).
It is not a bug in this library, there is no way around it.
Comments count
1import { FacebookProvider, CommentsCount } from 'react-facebook'; 2 3export default function CommentsCountExample() { 4 return ( 5 <FacebookProvider appId="123456789"> 6 <CommentsCount href="http://www.facebook.com" /> 7 </FacebookProvider> 8 ); 9}
useLogin
1import { FacebookProvider, useLogin } from 'react-facebook'; 2 3export default function LoginExample() { 4 const { login, status, isLoading, error} = useLogin(); 5 6 async function handleLogin() { 7 try { 8 const response = await login({ 9 scope: 'email', 10 }); 11 12 console.log(response.status); 13 } catch (error: any) { 14 console.log(error.message); 15 } 16 } 17 18 return ( 19 <button onClick={handleLogin} disabled={isLoading}> 20 Login via Facebook 21 </button> 22 ); 23}
LoginButton
1import { FacebookProvider, LoginButton } from 'react-facebook'; 2 3export default function LoginButtonExample() { 4 functon handleSuccess(response) { 5 console.log(response.status); 6 } 7 8 function handleError(error) { 9 console.log(error); 10 } 11 12 return ( 13 <FacebookProvider appId="123456789"> 14 <LoginButton 15 scope="email" 16 onError={handleError} 17 onSuccess={handleSuccess} 18 > 19 Login via Facebook 20 </LoginButton> 21 </FacebookProvider> 22 ); 23}
Embedded post
1import { FacebookProvider, EmbeddedPost } from 'react-facebook'; 2 3export default function EmbeddedPostExample() { 4 return ( 5 <FacebookProvider appId="123456789"> 6 <EmbeddedPost href="http://www.facebook.com" width="500" /> 7 </FacebookProvider> 8 ); 9}
Page
1import React, { Component} from 'react'; 2import { FacebookProvider, Page } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <Page href="https://www.facebook.com" tabs="timeline" /> 9 </FacebookProvider> 10 ); 11 } 12}
Feed
1import React, { Component} from 'react'; 2import { FacebookProvider, Feed } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <Feed link="https://www.facebook.com"> 9 {({ handleClick }) => ( 10 <button type="button" onClick={handleClick}>Share on Feed</button> 11 )} 12 </Feed> 13 </FacebookProvider> 14 ); 15 } 16}
Group
1import React, { Component } from 'react'; 2import { FacebookProvider, Group } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <Group 9 href="https://www.facebook.com/groups/375934682909754" 10 width="300" 11 showSocialContext={true} 12 showMetaData={true} 13 skin="light" 14 /> 15 </FacebookProvider> 16 ); 17 } 18}
MessageUs
1import React, { Component} from 'react'; 2import { FacebookProvider, MessageUs } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <MessageUs messengerAppId="123456789" pageId="123456789"/> 9 </FacebookProvider> 10 ); 11 } 12}
SendToMessenger
1import React, { Component} from 'react'; 2import { FacebookProvider, SendToMessenger } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <SendToMessenger messengerAppId="123456789" pageId="123456789"/> 9 </FacebookProvider> 10 ); 11 } 12}
MessengerCheckbox
1import React, { Component} from 'react'; 2import { FacebookProvider, MessengerCheckbox } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789"> 8 <MessengerCheckbox messengerAppId="123456789" pageId="123456789"/> 9 </FacebookProvider> 10 ); 11 } 12}
CustomChat
1import React, { Component} from 'react'; 2import { FacebookProvider, CustomChat } from 'react-facebook'; 3 4export default class Example extends Component { 5 render() { 6 return ( 7 <FacebookProvider appId="123456789" chatSupport> 8 <CustomChat pageId="123456789" minimized={false}/> 9 </FacebookProvider> 10 ); 11 } 12}
API Access
1import { FacebookProvider, useFacebook } from 'react-facebook'; 2 3export default function UseFacebookExample() { 4 const { isLoading, init, error } = useFacebook(); 5 6 async function handleClick() { 7 const api = await init(); 8 9 const response = await api.login(); 10 const FB = await api.getFB(); // Get original FB object 11 } 12 13 return ( 14 <button disabled={isLoading} onClick={handleClick}> 15 Login 16 </button> 17 ); 18}
useSubscribe - Subscribe to events
1import { FacebookProvider, useSubscribe } from 'react-facebook'; 2 3export default function UseSubscribeExample() { 4 const latestValue = useSubscribe('auth.statusChange', (value) => { 5 console.log('new response', value); 6 }); 7 8 return ( 9 <div> 10 {latestValue} 11 </div> 12 ); 13}
useLoginStatus - read login status of current user
1import { FacebookProvider, useLoginStatus } from 'react-facebook'; 2 3export default function UseLoginStatusExample() { 4 const { status, isLoading, error } = useLoginStatus(); 5 6 return ( 7 <div> 8 Current user login status: {isLoading ? 'Loading...' : status} 9 </div> 10 ); 11}
User Profile
This component will not sign user. You need to do that with another component. Default scope: 'id', 'first_name', 'last_name', 'middle_name', 'name', 'name_format', 'picture', 'short_name', 'email'. If profile is undefined login status !== LoginStatus.CONNECTED
1import { FacebookProvider, useProfile } from 'react-facebook'; 2 3export default function UseProfileExample() { 4 const { profile, isLoading, error } = useProfile(['id', 'name']); 5 6 return ( 7 <div> 8 {profile?.name} has id: {profile?.id} 9 </div> 10 ); 11}
Testing
1npx cypress open --component
Support
Become my sponsor and help me maintain this project. Thank you
Credits
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-facebook
react-facebook-login
A Component React for Facebook Login
warning
A mirror of Facebook's Warning
react-player
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
@greatsumini/react-facebook-login
Well-typed React Component for Facebook Login