@greatsumini/react-facebook-login

中文文档
3.4.0发布于 2024/12/25MITTypeScriptCommonJS零依赖近 30 天下载 16.5万

Well-typed React Component for Facebook Login

原始使用文档
文档目录10 节
  1. Table of contents
  2. Getting Started
  3. Usage
  4. Component
  5. FacebookLoginClient
  6. Examples
  7. Props
  8. Stay in touch
  9. License
  10. Links

React Facebook Login

NPM version NPM downloads NPM bundle size CI CD GitHub Stars


React Component for Facebook Login. aims to improve react-facebook-login.
한글 가이드

  • 💙 Typescript support
  • 📦 6kb mini library
  • 👫 All browsers supported
  • 🏃 Currently maintaining

Table of contents

Getting Started

npm i --save @greatsumini/react-facebook-login
# or
yarn add @greatsumini/react-facebook-login

Usage

Component

import FacebookLogin from '@greatsumini/react-facebook-login';

// default
<FacebookLogin
  appId="1088597931155576"
  onSuccess={(response) => {
    console.log('Login Success!', response);
  }}
  onFail={(error) => {
    console.log('Login Failed!', error);
  }}
  onProfileSuccess={(response) => {
    console.log('Get Profile Success!', response);
  }}
/>

// custom style
<FacebookLogin
  appId="1088597931155576"
  style={{
    backgroundColor: '#4267b2',
    color: '#fff',
    fontSize: '16px',
    padding: '12px 24px',
    border: 'none',
    borderRadius: '4px',
  }}
/>

// custom render function
<FacebookLogin
  appId="1088597931155576"
  onSuccess={(response) => {
    console.log('Login Success!', response);
  }}
  onFail={(error) => {
    console.log('Login Failed!', error);
  }}
  onProfileSuccess={(response) => {
    console.log('Get Profile Success!', response);
  }}
  render={({ onClick, logout }) => (
    <CustomComponent onClick={onClick} onLogoutClick={logout} />
  )}
/>

// custom params, options
<FacebookLogin
  appId="1088597931155576"
  useRedirect
  initParams={{
    version: 'v10.0',
    xfbml: true,
  }}
  dialogParams={{
    response_type: 'token',
  }}
  loginOptions={{
    return_scopes: true,
  }}
/>

FacebookLoginClient

You can manually call facebook sdk related functions with FacebookLoginClient

import { FacebookLoginClient } from '@greatsumini/react-facebook-login';

FacebookLoginClient.getLoginStatus((res) => {
  console.log(res.status);
});

FacebookLoginClient.login((res) => {
  console.log(res);
});

FacebookLoginClient.getProfile((res) => {
  console.log(res.id, res.name, res.email);
});

FacebookLoginClient.logout(() => {
  console.log('logout completed!');
});

Examples

You can checkout examples here

Props

Check all available params,options here

PropertyDescriptionTypeDefault
appId *Your application ID.string-
languageAPI versionstring'en_US'
scopeComma seperated list of permissions for login.string'public_profile, email'
fieldsfields return by /me (profile)string'name,email,picture'
onSuccessfunction-
onFailfunction-
onProfileSuccessfunction-
stylecss properties for login buttonCSSProperties-
childrenChildren ComponentReactNode | ReactNodeArray"Login with Facebook"
renderCallback which render custom componentfunction-
autoLoadif true, request login on mountbooleanfalse
useRedirectif true, use redirect instead of window.FB.loginbooleanfalse (forced to be true in fb browers (ref))
useCustomChatif true, append 'xfbml.customerchat' to sdk urlbooleanfalse
initParamsparams for FB.initInitParamsdocs
dialogParamsparams for login dialogDialogParamsdocs
loginOptionsoptions for FB.loginLoginOptionsdocs

Stay in touch

License

React Facebook Login is MIT licensed.

版本与发布记录

@greatsumini/react-facebook-login 共发布 44 个版本,首次发布于 2021/04/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.4.0latest2024/12/251.9 年前
3.3.32023/04/043 年前
3.3.22023/02/153 年前
3.3.12022/12/273 年前
3.3.02022/12/053 年前
3.2.12022/07/214 年前

关于 @greatsumini/react-facebook-login 的常见问题

@greatsumini/react-facebook-login 是什么?

Well-typed React Component for Facebook Login

如何安装 @greatsumini/react-facebook-login?

在项目目录运行 npm install @greatsumini/react-facebook-login,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@greatsumini/react-facebook-login 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@greatsumini/react-facebook-login 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@greatsumini/react-facebook-login 可以商用吗?

@greatsumini/react-facebook-login 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@greatsumini/react-facebook-login 的下载量有多少?

根据 npm 官方下载统计,@greatsumini/react-facebook-login 在 2026/10/17 – 2026/11/15 这 30 天内被下载 165,436 次,日均约 5,515 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@greatsumini/react-facebook-login 还在维护吗?

最新版本 3.4.0 发布于 2024/12/25(1.9 年前);至今共发布 44 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。