Skip to content

Commit

Permalink
createAppHook(): let consumers pass the connector configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Aug 21, 2020
1 parent 092828d commit f0dbc28
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/connect-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ export function usePermissions(): [Permission[], LoadingStatus] {
return useConnectSubscription<Permission[]>(callback, [])
}

export function createAppHook(appConnect: Function) {
export function createAppHook(
appConnect: Function,
connector?: string | [string, { [key: string]: any } | undefined]
) {
return function useAppData<T = any>(
app: App | null,
callback?: (app: App | any) => T | Promise<T>
Expand All @@ -208,7 +211,7 @@ export function createAppHook(appConnect: Function) {
setLoading(true)

try {
const connectedApp = await appConnect(app)
const connectedApp = await appConnect(updatedApp, connector)
const result = await callbackRef.current(connectedApp)
if (!cancelled) {
setLoading(false)
Expand All @@ -229,7 +232,7 @@ export function createAppHook(appConnect: Function) {
return () => {
cancelled = true
}
}, [app])
}, [connector, app])

return [result, { error, loading, retry: () => null }]
}
Expand Down

0 comments on commit f0dbc28

Please sign in to comment.