Skip to content

A custom React hook to integrate Facebook JavaScript SDK in React apps

License

Notifications You must be signed in to change notification settings

jabranr/use-facebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Jabran Rafique
Oct 27, 2023
f60a14c · Oct 27, 2023

History

18 Commits
Oct 27, 2023
Feb 20, 2023
Oct 17, 2020
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023

Repository files navigation

use-facebook Node.js Package

Custom React hook for Facebook JavaScript SDK

use facebook

Installation

npm install use-facebook

Usage

Here is an example demostrating a button that triggers Facebook login dialog. Some of the code is truncated for brevity.

import React from 'react';
import useFacebook from 'use-facebook';

export default function MyFacebookLoginPage () {
  /**
   * options is an object (also detailed below)
   */
   const options = { appId: '123456789' };

  /**
   * Returns the state of SDK (true = loaded and ready to use)
   */
  const { isFacebookSDKReady } = useFacebook(options);


  /**
   * Enable/disable the button based on SDK ready state
   * Show FB login dialog on click once enabled
   */
  return (
   <button disabled={!isFacebookSDKReady} onClick={() => FB.login()}>Connect with Facebook</button>
  );
}

Read Facebook SDK docs for FB API usage.

options

options = {
  appId: 'abcxyz',
  version: "v18.0",
  autoLogAppEvents: true,
  xfbml: true,
  debug: false,
  lang: "en_GB",
}

appId is required and everything else is optional.

License

MIT License

© 2020 - present Jabran Rafique (@jabranr)