Skip to content

Commit

Permalink
added useShare
Browse files Browse the repository at this point in the history
  • Loading branch information
seeden committed Mar 25, 2019
1 parent f93e2a1 commit e2d8fcc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ script: npm test
notifications:
email:
recipients:
- zlatkofedor@cherryprojects.com
- zfedor@gmail.com
on_success: change
on_failure: always
35 changes: 17 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-facebook",
"version": "7.0.6",
"version": "7.1.0",
"description": "Facebook components like a Login button, Like, Share, Comments, Embedded Post/Video, Messenger Chat and others",
"author": {
"name": "Zlatko Fedor",
Expand Down Expand Up @@ -57,15 +57,15 @@
]
},
"dependencies": {
"@babel/runtime": "^7.3.4",
"@babel/runtime": "^7.4.2",
"can-use-dom": "^0.1.0",
"react-spinner-children": "^1.0.8"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-decorators": "^7.3.0",
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-proposal-do-expressions": "^7.2.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
Expand All @@ -79,29 +79,28 @@
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.3.4",
"@babel/plugin-transform-flow-strip-types": "^7.4.0",
"@babel/plugin-transform-proto-to-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.3.1",
"babel-jest": "^24.5.0",
"cross-env": "^5.2.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.10.0",
"eslint": "^5.15.1",
"enzyme-adapter-react-16": "^1.11.2",
"eslint": "^5.15.3",
"eslint-config-airbnb": "^17.1.0",
"eslint-loader": "^2.1.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"jest": "^24.3.1",
"jest-cli": "^24.3.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-test-renderer": "^16.8.4"
"jest": "^24.5.0",
"jest-cli": "^24.5.0",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"react-test-renderer": "^16.8.5"
},
"peerDependencies": {
"react": "16.x"
Expand Down
4 changes: 4 additions & 0 deletions src/FacebookContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow
import { createContext } from 'react';

export default createContext();
4 changes: 2 additions & 2 deletions src/FacebookProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow
import React, { Component, createContext, type Node } from 'react';
import React, { Component, type Node } from 'react';
import canUseDOM from 'can-use-dom';
import FB from './Facebook';
import FacebookContext from './FacebookContext';

export const FacebookContext = createContext();
let api = null;

type Props = {
Expand Down
34 changes: 34 additions & 0 deletions src/hooks/useShare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @flow
import { useContext } from 'react';
import clearUndefinedProperties from '../utils/clearUndefinedProperties';
import FacebookContext from '../FacebookContext';

export default () => {
const { api } = useContext(FacebookContext);

function handleShare(options: Object) {
const {
href,
display,
hashtag,
redirectUri,
quote,
mobileIframe,
...rest
} = options;

return api.ui(clearUndefinedProperties({
method: 'share',
href,
display,
app_id: api.getAppId(),
hashtag,
redirect_uri: redirectUri,
quote,
mobile_iframe: mobileIframe,
...rest,
}));
}

return handleShare;
};
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ export MessengerColor from './constants/MessengerColor';

export LoginStatus from './constants/LoginStatus';
export Fields from './constants/Fields';

export FacebookContext from './FacebookContext';

export useShare from './hooks/useShare';

0 comments on commit e2d8fcc

Please sign in to comment.