npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-easy-facebook

v0.1.7

Published

An abstracted approach to handling Facebook OAuth using Hooks and Typescript!

Downloads

146

Readme

react-easy-facebook

An abstracted approach to handling Facebook OAuth using Hooks and Typescript!

Requires react >= 16.8.0

Installation

Install the package using your package manager of choice.

$ npm install react-easy-facebook
$ yarn add react-easy-facebook

Usage

Basic demo

import react from "react";
import useFacebook from "react-easy-facebook";

const App = () => {
  /* Initializing the hook by giving it the facebook app id. */

  const { response, login, logout } = useFacebook({
    appId: "5135128098923510",
  });

  const handleLogin = () => {
    login();
  };

  const handleLogout = () => {
    logout();
  };

  /*
   response is a react state so subscribe to its updates however you'd like to.
   Here, I'm printing it inside a useEffect.
  */

  React.useEffect(() => {
    if (response) console.log(response);
  }, [response]);

  /* Trigger the login action by calling login() */
  /* Similarly, trigger the logout action by calling logout() */

  return (
    <>
      <button onClick={handleLogin}>login</button>
      <button onClick={handleLogout}>logout</button>
    </>
  );
};

Using with custom scopes

const { response, login } = useFacebook({
  appId: "5135128098923510",
  options: {
    scope: ["email", "user_birthday"],
  },
});

Or

const { response, login } = useFacebook({
  appId: "5135128098923510",
  options: {
    scope: "email,user_birthday",
  },
});

Using with custom scopes and fields

const { response, login } = useFacebook({
  appId: "5135128098923510",
  options: {
    scope: ["email", "user_birthday"],
  },
  fields: ["id", "name", "email"],
});

Or

const { response, login } = useFacebook({
  appId: "5135128098923510",
  options: {
    scope: "email,user_birthday",
  },
  fields: "id,name,email",
});

Generally, you should use the array syntax to get Intellisense hints. But you'll always need to use the string syntax when hitting an edge like picture.

Example

const { response, login } = useFacebook({
  appId: "5135128098923510",
  options: {
    scope: "email",
  },
  fields: "id,name,email,picture{height,width,url,is_silhouette}",
});

For more information about the different fields and edges, visit the Facebook docs.

Calling login() with different fields

You may override the fields specified in the hook initialization by passing the new fields to the login function.

const App = () => {
  const { response, login } = useFacebook({
    appId: "5135128098923510",
    fields: ["id", "email"],
  });

  const handleLogin = () => {
    login(["id", "email", "name"]);
    // or
    // login("id,email,name")
  };

  React.useEffect(() => {
    if (response) console.log(response);
  }, [response]);

  return <button onClick={handleLogin}>login</button>;
};

Error Handling

const App = () => {
  const { response, login } = useFacebook({
    appId: "5135128098923510",
    // Add error handling logic here
    // By default, it does console.error()
    handleError: (error) => {
      console.error(error);
    },
  });

  const handleLogin = () => {
    login();
  };

  React.useEffect(() => {
    if (response) console.log(response);
  }, [response]);

  return <button onClick={handleLogin}>login</button>;
};

Development

Install the project dependencies and run yarn link.

$ yarn
$ yarn link

Navigate to the project you'd like to test the package in and run the following command to link the package to your local project.

$ cd path/to/your_local_project
$ yarn link react-easy-facebook

Now, simply start you local project.

If you get the rules of hooks error, do the instructions specified in this issue

LICENSE

MIT