1

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?

1 Answers1

0

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/

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • yeah, I have been trying to do that with dynamical method but I guess there is no way. how can I make it work? for now am trying to make it work using react-helmet-async, but I dont think that it will work. I cant just add it statically, because am fetching images from api. any tips on how to make it work? – Y U K I M U R A Nov 11 '22 at 09:50
  • you really have to generate the og tags serverside, there is no way around that... – andyrandy Nov 11 '22 at 09:54
  • willl pre-render help my case? – Y U K I M U R A Nov 11 '22 at 10:10
  • i dont know your code, but as long as the source includes the og tags without any javascript, it is fine – andyrandy Nov 11 '22 at 11:17