项目作者: jabranr

项目描述 :
Custom React hook for Facebook JavaScript SDK
高级语言: JavaScript
项目地址: git://github.com/jabranr/use-facebook.git
创建时间: 2020-10-17T00:31:39Z
项目社区:https://github.com/jabranr/use-facebook

开源协议:MIT License

下载


use-facebook Node.js Package

Custom React hook for Facebook JavaScript SDK

use facebook

Installation

  1. 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.

  1. import React from 'react';
  2. import useFacebook from 'use-facebook';
  3. export default function MyFacebookLoginPage () {
  4. /**
  5. * options is an object (also detailed below)
  6. */
  7. const options = { appId: '123456789' };
  8. /**
  9. * Returns the state of SDK (true = loaded and ready to use)
  10. */
  11. const { isFacebookSDKReady } = useFacebook(options);
  12. /**
  13. * Enable/disable the button based on SDK ready state
  14. * Show FB login dialog on click once enabled
  15. */
  16. return (
  17. <button disabled={!isFacebookSDKReady} onClick={() => FB.login()}>Connect with Facebook</button>
  18. );
  19. }

Read Facebook SDK docs for FB API usage.

options

  1. options = {
  2. appId: 'abcxyz',
  3. version: "v18.0",
  4. autoLogAppEvents: true,
  5. xfbml: true,
  6. debug: false,
  7. lang: "en_GB",
  8. }

appId is required and everything else is optional.

License

MIT License

© 2020 - present Jabran Rafique (@jabranr)