index.js

import React from 'react';
import Button from '../button';
import useNavigatorShare from '../../../hooks/share/useNavigatorShare';

import './index.scss';

export default function ShareBtn({ data }) {
  const { isSupported, share } = useNavigatorShare();

  function clickHandler() {
    share(data);
  }

  function copyToClipboard() {
    const pageUrl = window.location.href;
    navigator.clipboard.writeText(pageUrl);
  }

  return isSupported ? (
    <Button buttonId="share-btn" buttonText="Share" iconId="share" onClickHandler={clickHandler} category="secondary" />
  ) : (
    <Button
      buttonId="copy-btn"
      buttonText="Copy Link"
      iconId="copy"
      onClickHandler={copyToClipboard}
      category="secondary"
    />
  );
}