66
77/* @flow */
88
9- import React from 'react' ;
9+ import React , { useContext , useEffect } from 'react' ;
1010import { ReactRelayContext } from 'react-relay' ;
11+ import { fb } from './utils' ;
1112
1213// Default history object (for unit tests)
1314const history = { location : { pathname : '/' } } ;
@@ -17,17 +18,24 @@ export const HistoryContext = React.createContext(history);
1718export const ResetContext = React . createContext ( ( ) => { } ) ;
1819
1920export function useConfig ( ) {
20- return React . useContext ( ConfigContext ) ;
21+ return useContext ( ConfigContext ) ;
2122}
2223
2324export function useHistory ( ) {
24- return React . useContext ( HistoryContext ) ;
25+ return useContext ( HistoryContext ) ;
2526}
2627
2728export function useRelay ( ) {
28- return React . useContext ( ReactRelayContext ) ;
29+ return useContext ( ReactRelayContext ) ;
2930}
3031
3132export function useReset ( ) {
32- return React . useContext ( ResetContext ) ;
33+ return useContext ( ResetContext ) ;
34+ }
35+
36+ export function useFacebookEvent ( event , callback , deps = [ ] ) {
37+ useEffect ( ( ) => {
38+ fb ( FB => FB . Event . subscribe ( event , callback ) , { async : false } ) ;
39+ return fb ( FB => FB . Event . unsubscribe ( event , callback ) , { async : false } ) ;
40+ } , deps ) ;
3341}
0 commit comments