Rahul Ramesh
Rahul Ramesh

Reputation: 91

How do I post to facebook from my React app?

Currently have an app with React on the Front end, and Rails on the back end. Want to post stuff to facebook. Any tips for tutorials that I could use?

Upvotes: 2

Views: 5330

Answers (2)

Sivadass N
Sivadass N

Reputation: 927

You can create Facebook Share Button component fair easily by yourself. Just pass the URL you want to share to fb as a param in URL which is provided by Facebook:

`https://facebook.com/sharer/sharer.php?u=${encodedURL}`

I've built a react component for you:

class FBShareButton extends React.Component{
  constructor(props){
    super(props);
    this.state = {
     url : this.props.url
    }
  }

  render(){
    let encodedURL = encodeURI(this.state.url);
    return(
      <a href={`https://facebook.com/sharer/sharer.php?u=${encodedURL}`}>Share on Facebook</a>
    )
  }
}

ReactDOM.render(
  <FBShareButton url={"https://stackoverflow.com"} />, document.getElementById('root')
)

Also check the demo here.

Upvotes: 7

Scott
Scott

Reputation: 3765

React + Facebook + Open Source = here's one option: https://www.npmjs.com/package/react-facebook

Upvotes: 0

Related Questions