Search code examples
reactjsfacebooktwitterreact-share

is there a way to share react page on Facebook and pass an image?


am trying to make my react page shareable on Facebook and Twitter. I tried everything I could, I have been googling all day, but I cant find the answer.

 <FacebookShareButton url={window.location.href} title={exactNews.text ?exactNews.title : ""}> 
      <FaFacebookF/>
 </FacebookShareButton>

any tips?


Solution

  • There is no way to pass an image to the share options anymore, the only way to add an image to a shared URL is by using the og:image tag in the source. Be aware that Facebook ignores JavaScript, so the og:image tag must be in the original source and not dynamically added via JavaScript. Facebook then automatically uses the image specified in the og:image tag.

    More information: https://ogp.me/

    You can use https://prerender.io/benefits/social-media-sharing/ or a framework like Next.js to render pages server side, with the correct OG images.