File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed
Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1+ // @flow
2+ import { useContext , useState } from 'react' ;
3+ import FacebookContext from '../FacebookContext' ;
4+
5+ export default ( onReady ? : Function ) => {
6+ const {
7+ handleInit,
8+ api,
9+ } = useContext ( FacebookContext ) ;
10+
11+ useState ( async ( ) => {
12+ const api2 = await handleInit ( ) ;
13+ if ( onReady ) {
14+ onReady ( api2 ) ;
15+ }
16+ } ) ;
17+
18+ return [ api , handleInit ] ;
19+ } ;
Original file line number Diff line number Diff line change 11// @flow
2- import { useContext } from 'react' ;
32import clearUndefinedProperties from '../utils/clearUndefinedProperties' ;
4- import FacebookContext from '../FacebookContext ' ;
3+ import useApi from './useApi ' ;
54
65export default ( ) => {
7- const { api } = useContext ( FacebookContext ) ;
6+ const [ , prepareApi ] = useApi ( ) ;
87
9- function handleShare ( options : Object ) {
8+ async function handleShare ( options : Object ) {
109 const {
1110 href,
1211 display,
@@ -17,6 +16,8 @@ export default () => {
1716 ...rest
1817 } = options ;
1918
19+ const api = await prepareApi ( ) ;
20+
2021 return api . ui ( clearUndefinedProperties ( {
2122 method : 'share' ,
2223 href,
Original file line number Diff line number Diff line change @@ -41,3 +41,4 @@ export Fields from './constants/Fields';
4141export FacebookContext from './FacebookContext' ;
4242
4343export useShare from './hooks/useShare' ;
44+ export useApi from './hooks/useApi' ;
You can’t perform that action at this time.
0 commit comments