nygardk / react-share

Social media share buttons and share counts for React
MIT License
2.63k stars 433 forks source link

unable to share my react web page to instagram,this my code to share current page to social media #458

Open vikkkz opened 2 years ago

vikkkz commented 2 years ago

`import React, { useEffect, useState } from "react"; import { Grid, Typography, makeStyles, IconButton, Button, } from "@material-ui/core"; import { Link } from "react-router-dom"; import styles from "../DIseaseWithQues/styles"; import ShareArrow from "../../../assets/images/shareArrow.svg"; import whatsappShare from "../../../assets/images/whatsappShare.svg"; import twitterShare from "../../../assets/images/twitterShare.svg"; import facebookShare from "../../../assets/images/facebookShare.svg"; import instagramShare from "../../../assets/images/instagramShare.svg"; import shareClose from "../../../assets/images/shareClose.svg"; import { FacebookShareButton, InstapaperShareButton } from "react-share"

const useStyles = makeStyles((theme) => styles(theme));

const Share = () => { const classes = useStyles(); const [showSocial, setShowSocial] = useState(false); const[currentpageurl,setCurrentPageUrl]= useState("") const[currentpage,setCurrentPage] = useState("")

useEffect(() =>{ setCurrentPage(window.location.pathname) setCurrentPageUrl(window.location.href) },) console.log(window.location.pathname,"currentpageurl")

// const encode = ()=>{ // encodeURIComponent(currentpageurl) // replace("%[1-9]","") // }

const _whatsappShare = () => { window.open("https://web.whatsapp.com/send?text=/" + currentpageurl, "_blank") }

const _twitterShare = () => { window.open("https://twitter.com/intent/tweet?url=/" + currentpageurl, "_blank") }

const _fbShare = () => { window.open("https://www.facebook.com/sharer.php?u=/" + currentpageurl, "_blank") }

const _instaShare = () => { // window.open("https://www.instagram.com/send?text=" + currentpageurl, "_blank") window.open( "https://www.instagram.com/accounts/onetap/?next=" + "http://test-consumer.doctall.com" ); console.log(currentpageurl,"currentpageurl") }

return ( <> {showSocial ? ( console.log(showSocial,"showSocial"), <Grid item container className={classes.socialIcons} justifyContent="space-evenly" alignItems="center"

whatsapp whatsapp
      </IconButton>
      <IconButton onClick={_instaShare}>
        {/* <InstapaperShareButton
         url={"http://test-new.doctall.com/hair-loss"}
         title = { " " }
         description = { " " }
        > */}
        <img src={instagramShare} alt="whatsapp" />
        {/* </InstapaperShareButton> */}
      </IconButton>
      <IconButton
        style={{
          width: "42px",
          height: "42px",
          background: "#004451",
          borderRadius: "50%",
        }}
        onClick={() => setShowSocial(false)}
      >
        <img src={shareClose} alt="whatsapp" />
      </IconButton>
    </Grid>
  ) : (
    <Grid
      item
      container
      direction="column"
      className={classes.shareIcon}
      justifyContent="center"
      alignItems="center"
      onClick={() => setShowSocial(true)}
    >
      <IconButton>
        <img src={ShareArrow} alt="arrow" />
      </IconButton>
      <Typography
        style={{
          fontStyle: "normal",
          fontWeight: "bold",
          fontSize: "12px",
          lineHeight: "16px",
          color: "#FFFFFF",
        }}
      >
        Share
      </Typography>
    </Grid>
  )}
</>

); };

export default Share; `