# STEP-10 SocialShare Component Development

[**STEP-10**](https://github.com/GAkim/SocialShareGraphQl/tree/STEP-10)

{% embed url="<https://www.youtube.com/watch?v=ZAatv1bg5eU>" %}

1. We need to add [**react share**](https://www.npmjs.com/package/react-share) package, for that modifying your extension **package.json**

{% code title="scandipwa/packages/scandipwa-socialshare/package.json" %}

```javascript
{
   "name": "scandipwa-socialshare",
   "version": "0.0.1",
   "license": "OSL-3.0",
   "scandipwa": {
       "type": "extension"
   },
   "dependencies": {
       "react-share": "4.4.0"
   },
   "eslintConfig": {
       "extends": "@scandipwa"
   }
}
```

{% endcode %}

2\. Run `npm install` at theme folder, in order to pull packages, then restart frontend

3\. Create **SocialShare.config.js** in **SOURCE/component/SocialShare**

{% code title="scandipwa-socialshare/src/component/SocialShare/SocialShare.config.js" %}

```javascript
export const FACEBOOK = 'facebook';
export const FACEBOOK_MSG = 'facebook_messenger';
export const TELEGRAM = 'telegram';
export const WHATSAPP = 'whatsapp';
export const LINKEDIN = 'linkedin';
export const EMAIL = 'email';
```

{% endcode %}

4\. Modify **SocialShare.component.js**

{% code title="scandipwa-socialshare/src/component/SocialShare/SocialShare.component.js" %}

```javascript
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import {
   EmailIcon,
   EmailShareButton,
   FacebookIcon,
   FacebookMessengerIcon,
   FacebookMessengerShareButton,
   FacebookShareButton,
   FacebookShareCount,
   LinkedinIcon,
   LinkedinShareButton,
   TelegramIcon,
   TelegramShareButton,
   WhatsappIcon,
   WhatsappShareButton
} from 'react-share';

import {
   EMAIL,
   FACEBOOK,
   FACEBOOK_MSG,
   LINKEDIN,
   TELEGRAM,
   WHATSAPP
} from './SocialShare.config';

import './SocialShare.style';

/** @namespace ScandipwaSocialshare/Component/SocialShare/Component/SocialShareComponent */
export class SocialShareComponent extends PureComponent {
   static propTypes = {
       providers: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
       size: PropTypes.string.isRequired,
       isRounded: PropTypes.bool.isRequired,
       quote: PropTypes.string.isRequired
   };

   renderMap = {
       [FACEBOOK]: {
           render: (counter, additional, shareUrl) => this.renderFaceBook(counter, additional, shareUrl)
       },
       [EMAIL]: {
           render: (counter, additional, shareUrl) => this.renderEmail(counter, additional, shareUrl)
       },
       [FACEBOOK_MSG]: {
           render: (counter, additional, shareUrl) => this.renderMessenger(counter, additional, shareUrl)
       },
       [TELEGRAM]: {
           render: (counter, additional, shareUrl) => this.renderTelegram(counter, additional, shareUrl)
       },
       [WHATSAPP]: {
           render: (counter, additional, shareUrl) => this.renderWhatsApp(counter, additional, shareUrl)
       },
       [LINKEDIN]: {
           render: (counter, additional, shareUrl) => this.renderLinkedIn(counter, additional, shareUrl)
       }
   };

   renderLinkedIn(counter, additional, shareUrl) {
       const { size, isRounded } = this.props;

       return (
           <LinkedinShareButton
             url={ shareUrl }
           >
               <LinkedinIcon
                 size={ size }
                 round={ isRounded }
               />
           </LinkedinShareButton>
       );
   }

   renderFaceBook(counter, _, shareUrl) {
       const { size, isRounded, quote } = this.props;

       return (
           <>
               <FacebookShareButton
                 url={ shareUrl }
                 quote={ quote }
               >
                   <FacebookIcon
                     size={ size }
                     round={ isRounded }
                   />
               </FacebookShareButton>
               { this.renderFaceBookCounter(counter, shareUrl) }
           </>
       );
   }

   renderMessenger(counter, additional, shareUrl) {
       const { size, isRounded } = this.props;

       return (
           <FacebookMessengerShareButton
             url={ shareUrl }
             appId={ additional }
           >
               <FacebookMessengerIcon
                 size={ size }
                 round={ isRounded }
               />
           </FacebookMessengerShareButton>
       );
   }

   renderTelegram(counter, additional, shareUrl) {
       const { size, isRounded, quote } = this.props;

       return (
           <TelegramShareButton
             url={ shareUrl }
             title={ quote }
           >
               <TelegramIcon
                 size={ size }
                 round={ isRounded }
               />
           </TelegramShareButton>
       );
   }

   renderWhatsApp(counter, additional, shareUrl) {
       const { size, isRounded, quote } = this.props;

       return (
           <WhatsappShareButton
             url={ shareUrl }
             title={ quote }
             separator=" | "
           >
               <WhatsappIcon
                 size={ size }
                 round={ isRounded }
               />
           </WhatsappShareButton>
       );
   }

   // Counter is not working for now https://github.com/nygardk/react-share/issues/347
   // TODO: Update package when issue will be fixed
   renderFaceBookCounter(counter, shareUrl) {
       if (!counter) {
           return null;
       }

       return (
           <FacebookShareCount url={ shareUrl }>
               { (count) => count }
           </FacebookShareCount>
       );
   }

   renderEmail(counter, additional, shareUrl) {
       const { size, isRounded, quote } = this.props;

       return (
           <EmailShareButton
             url={ shareUrl }
             subject={ `${additional} | ${quote}` }
           >
               <EmailIcon size={ size } round={ isRounded } />
           </EmailShareButton>
       );
   }

   renderProvider(provider) {
       const shareUrl = window.location.href;
       const { id, counter, additional } = provider;
       const { render } = this.renderMap[id];

       return (
           <div block="SocialShare" elem="Provider">
               { render(counter, additional, shareUrl) }
           </div>
       );
   }

   render() {
       const { providers } = this.props;

       return (
           <div block="SocialShare">
               { providers.map((provider) => this.renderProvider(provider)) }
           </div>
       );
   }
}

export default SocialShareComponent;
```

{% endcode %}

5\. Modify **SocialShare.style.scss**

{% code title="" %}

```javascript
.SocialShare {
   width: 100%;
   display: flex;
   flex-direction: row;
   justify-content: space-around;

   &-Provider {
       margin-right: 10px;
   }
}
```

{% endcode %}

6\. Go to you Frontend and check the result<br>

| **Mobile**                                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://lh6.googleusercontent.com/gHL8Bw1W7DqHJ7_DFkyRO6GL_NKHYDSpTV5JW4FH9geMfrEaw7l576vei0Nyo3mWT9f6uvD0zXwbkTgfb48w9bKRSPr-mjBpV7NinzOW7CePQWGW8R91R6OGAbuWJmh5Kv5-SgdN) |
| **Desktop**                                                                                                                                                                     |

![](https://lh3.googleusercontent.com/5p9ssH7lvmKSanXXYrtVgI86w69Otw0Y3Dx2BNZowpwWv34puQjRxtUHQSaLgQ4I5z1MqjhfWplxjm2lvi0d8_j7i9ubKEeBsngdgt4AW4yZjcvpsZxXxxCX49WCJTq1dYPH8GfF)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scandipwa.com/tutorials/scandipwa-social-share/step-10-socialshare-component-development.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
