Skip to content

Commit 7afd4f9

Browse files
authored
Fix hashtag sending through 'undefined' if empty (#20)
* Fix hashtag sending through 'undefined' if empty * Bump package version to 0.0.5
1 parent b8544d8 commit 7afd4f9

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@phntms/react-share",
33
"description": "An all-in-one React library to implement custom Sharing Meta and Social Media Sharing Buttons.",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"homepage": "https://github.com/phantomstudios/react-share#readme",

src/utils/getFacebookUrl.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ export interface FacebookProps extends BaseShareProps {
99
hashtag?: string;
1010
}
1111

12-
export const getFacebookUrl = ({ url, quote, hashtag }: FacebookProps) =>
13-
`https://www.facebook.com/sharer/sharer.php${objectToUrlParams({
12+
export const getFacebookUrl = ({
13+
url,
14+
quote,
15+
hashtag: suppliedHashtag,
16+
}: FacebookProps) => {
17+
let hashtag = suppliedHashtag;
18+
if (hashtag && hashtag.charAt(0) !== "#") hashtag = `#${hashtag}`;
19+
return `https://www.facebook.com/sharer/sharer.php${objectToUrlParams({
1420
u: url,
1521
quote,
16-
hashtag: hashtag?.charAt(0) === "#" ? hashtag : `#${hashtag}`,
22+
hashtag,
1723
})}`;
24+
};
1825

1926
export default getFacebookUrl;

0 commit comments

Comments
 (0)