react-facebook

WebJar for react-facebook

License

License

MIT
Categories

Categories

React User Interface Web Frameworks
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

react-facebook
Last Version

Last Version

4.0.13
Release Date

Release Date

Type

Type

jar
Description

Description

react-facebook
WebJar for react-facebook
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/CherryProjects/react-facebook

Download react-facebook

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/react-facebook/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>react-facebook</artifactId>
    <version>4.0.13</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/react-facebook/
implementation 'org.webjars.npm:react-facebook:4.0.13'
// https://jarcasting.com/artifacts/org.webjars.npm/react-facebook/
implementation ("org.webjars.npm:react-facebook:4.0.13")
'org.webjars.npm:react-facebook:jar:4.0.13'
<dependency org="org.webjars.npm" name="react-facebook" rev="4.0.13">
  <artifact name="react-facebook" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='react-facebook', version='4.0.13')
)
libraryDependencies += "org.webjars.npm" % "react-facebook" % "4.0.13"
[org.webjars.npm/react-facebook "4.0.13"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm » react-spinner-children jar [1.0.5,2)
org.webjars.npm : can-use-dom jar [0.1.0,0.2)
org.webjars.npm : prop-types jar [15.5.8,16)
org.webjars.npm : babel-runtime jar [6.23.0,7)

Project Modules

There are no modules declared in this project.

React Facebook Components

NPM version

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
  • Status
  • Subscribe
  • User Profile

Support us

Star this project on GitHub.

Initialisation

By default FacebookProvider is loading facebook script immediately with componentDidMount (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 wait to FacebookProvider. Use only one instance of the FacebookProvider on your page.

Usage

Like button

import React, { Component} from 'react';
import { FacebookProvider, Like } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Like href="http://www.facebook.com" colorScheme="dark" showFaces share />
      </FacebookProvider>
    );
  }
}

Share post

import React, { Component} from 'react';
import { FacebookProvider, Share } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Share href="http://www.facebook.com">
          {({ handleClick, loading }) => (
            <button type="button" disabled={loading} onClick={handleClick}>Share</button>
          )}
        </Share>
      </FacebookProvider>
    );
  }
}

Share button

You can use predefined button with bootstrap and font awesome classNames

import React, { Component} from 'react';
import { FacebookProvider, ShareButton } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <ShareButton href="http://www.facebook.com">
          Share
        </ShareButton>
      </FacebookProvider>
    );
  }
}

Comments

import React, { Component} from 'react';
import { FacebookProvider, Comments } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Comments href="http://www.facebook.com" />
      </FacebookProvider>
    );
  }
}

Comments count

import React, { Component} from 'react';
import { FacebookProvider, CommentsCount } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <CommentsCount href="http://www.facebook.com" />
      </FacebookProvider>
    );
  }
}

Login Button

import React, { Component} from 'react';
import { FacebookProvider, LoginButton } from 'react-facebook';

export default class Example extends Component {
  handleResponse = (data) => {
    console.log(data);
  }

  handleError = (error) => {
    this.setState({ error });
  }

  render() {
    return (
      <FacebookProvider appId="123456789">
        <LoginButton
          scope="email"
          onCompleted={this.handleResponse}
          onError={this.handleError}
        >
          <span>Login via Facebook</span>
        </LoginButton>
      </FacebookProvider>
    );
  }
}

Custom login render

If you want to use custom component you can use children as function.

import React, { Component} from 'react';
import { FacebookProvider, Login } from 'react-facebook';

export default class Example extends Component {
  handleResponse = (data) => {
    console.log(data);
  }

  handleError = (error) => {
    this.setState({ error });
  }

  render() {
    return (
      <FacebookProvider appId="123456789">
        <Login
          scope="email"
          onCompleted={this.handleResponse}
          onError={this.handleError}
        >
          {({ loading, handleClick, error, data }) => (
            <span onClick={handleClick}>
              Login via Facebook
              {loading && (
                <span>Loading...</span>
              )}
            </span>
          )}
        </Login>
      </FacebookProvider>
    );
  }
}

Embedded post

import React, { Component} from 'react';
import { FacebookProvider, EmbeddedPost } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <EmbeddedPost href="http://www.facebook.com" width="500" />
      </FacebookProvider>
    );
  }
}

Page

import React, { Component} from 'react';
import { FacebookProvider, Page } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Page href="https://www.facebook.com" tabs="timeline" />
      </FacebookProvider>    
    );
  }
}

Feed

import React, { Component} from 'react';
import { FacebookProvider, Feed } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Feed link="https://www.facebook.com">
          {({ handleClick }) => (
            <button type="button" onClick={handleClick}>Share on Feed</button>
          )}
        </Feed>
      </FacebookProvider>    
    );
  }
}

Group

import React, { Component } from 'react';
import { FacebookProvider, Group } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Group
          href="https://www.facebook.com/groups/375934682909754"
          width="300"
          showSocialContext={true}
          showMetaData={true}
          skin="light"
        />
      </FacebookProvider>    
    );
  }
}

MessageUs

import React, { Component} from 'react';
import { FacebookProvider, MessageUs } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <MessageUs messengerAppId="123456789" pageId="123456789"/>
      </FacebookProvider>    
    );
  }
}

SendToMessenger

import React, { Component} from 'react';
import { FacebookProvider, SendToMessenger } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <SendToMessenger messengerAppId="123456789" pageId="123456789"/>
      </FacebookProvider>    
    );
  }
}

MessengerCheckbox

import React, { Component} from 'react';
import { FacebookProvider, MessengerCheckbox } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <MessengerCheckbox messengerAppId="123456789" pageId="123456789"/>
      </FacebookProvider>    
    );
  }
}

CustomChat

import React, { Component} from 'react';
import { FacebookProvider, CustomChat } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789" chatSupport>
        <CustomChat pageId="123456789" minimized={false}/>
      </FacebookProvider>    
    );
  }
}

API Access

import React, { Component} from 'react';
import { FacebookProvider, Initialize } from 'react-facebook';

export default class Example extends Component {
  render() {
    return (
      <FacebookProvider appId="123456789">
        <Initialize>
          {({ isReady, api }) => {
            api.ui(...) // our custom async/await api
            // original FB api is available via window.FB
          }}
        <Initialize>
      </FacebookProvider>    
    );
  }
}

Subscribe

import React, { Component} from 'react';
import { FacebookProvider, Subscribe } from 'react-facebook';

export default class Example extends Component {
  handleChange = (response) => {
    console.log(response);
  } 

  render() {
    return (
      <FacebookProvider appId="123456789">
        <Subscribe event="auth.statusChange" onChange={this.handleChange} />
      </FacebookProvider>    
    );
  }
}

Login Status

import React, { Component} from 'react';
import { FacebookProvider, Status } from 'react-facebook';

export default class Example extends Component {
  handleChange = (response) => {
    console.log(response);
  } 

  render() {
    return (
      <FacebookProvider appId="123456789">
        <Status>
          {({ loading, status }) => (
            <div>
              {...}
            </div>
          )}
        </Status>
      </FacebookProvider>    
    );
  }
}

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

import React, { Component} from 'react';
import { FacebookProvider, Profile } from 'react-facebook';

export default class Example extends Component {
  handleChange = (response) => {
    console.log(response);
  } 

  render() {
    return (
      <FacebookProvider appId="123456789">
        <Profile>
          {({ loading, profile }) => (
            <div>
              {profile.picture}
              {profile.name} 
            </div>
          )}
        </Profile>
      </FacebookProvider>    
    );
  }
}

Support us

Star this project on GitHub.

Try our other React components

Credits

Zlatko Fedor

Versions

Version
4.0.13