MCPcopy Create free account
hub / github.com/TheOrcDev/github-creature / ShareOnXButton

Function ShareOnXButton

components/share-on-x-button.tsx:14–42  ·  view source on GitHub ↗
({
  text,
  className,
}: ShareOnXButtonProps)

Source from the content-addressed store, hash-verified

12}
13
14export default function ShareOnXButton({
15 text,
16 className,
17}: ShareOnXButtonProps) {
18 const [shareUrl, setShareUrl] = React.useState("");
19
20 React.useEffect(() => {
21 setShareUrl(window.location.href);
22 }, []);
23
24 const onClick = React.useCallback(() => {
25 const intentUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
26 text
27 )}&url=${encodeURIComponent(shareUrl)}`;
28 window.open(intentUrl, "_blank", "noopener,noreferrer");
29 }, [shareUrl, text]);
30
31 return (
32 <Button
33 variant="outline"
34 size="sm"
35 aria-label="Share on X"
36 className={className}
37 onClick={onClick}
38 disabled={!shareUrl}
39 >
40 <HugeiconsIcon icon={NewTwitterFreeIcons} />
41 </Button>
42 );
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected