Skip to content

Commit

Permalink
feat(mp): 新增 useShareAppMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 28, 2020
1 parent 19073ec commit b5b39fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './patchMiniProgram'
export * from './redirectPageTo'
export * from './submit'
export * from './usePullDownRefresh'
export * from './useShareAppMessage'
export * from './useSubmit'
export * from './useTopBarInfo'
// @endindex
18 changes: 18 additions & 0 deletions src/mp/useShareAppMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference types="miniprogram-api-typings" />
import { Defined } from '../types'
import { miniProgramBus } from './miniProgramBus'
import { useEffect } from 'react'
import { useLatest } from '../react'

export function useShareAppMessage(
callback: Defined<
WechatMiniprogram.Page.Options<{}, {}>['onShareAppMessage']
>,
): void {
const latestCallback = useLatest(callback)
useEffect(() => {
return miniProgramBus.on('currentPageShareAppMessage', (...args) => {
return latestCallback.current(...args)
})
}, [])
}

0 comments on commit b5b39fe

Please sign in to comment.