useShare.js 850B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { useRef } from 'react'
  2. import Taro, { useShareAppMessage } from '@tarojs/taro'
  3. import shareTracking from '@/utils/tracking/share'
  4. export default function useShare(shareContent, trackData) {
  5. const shareRef = useRef()
  6. const trackRef = useRef()
  7. shareRef.current = shareContent
  8. trackRef.current = trackData
  9. useShareAppMessage((res) => {
  10. const {
  11. title,
  12. path,
  13. image,
  14. } = shareRef.current || {}
  15. const {
  16. event = 'share',
  17. eventType,
  18. propertyName,
  19. consultantId,
  20. sharePersonId,
  21. targetId,
  22. buildingId,
  23. } = trackRef.current || {}
  24. // 分享埋点
  25. shareTracking({
  26. event,
  27. eventType,
  28. propertyName,
  29. consultantId,
  30. sharePersonId,
  31. targetId,
  32. buildingId,
  33. })
  34. return { title, path, imageUrl: image }
  35. })
  36. }