Chuyển tới nội dung chính

SDK 1.0.0

React hooks

import { usePoints, useSafeArea, useSDK, useTheme, useUser } from '@i-catholic/mini-app-sdk/react'
HookReturnsPermissionUpdates on
useSDK(){ sdk, inApp, theme, locale }nonethemeChange (locale: once)
useTheme()'light' | 'dark'nonethemeChange
useUser(){ user, loading, error, refetch }user.profilerefetch()
usePoints(){ points, loading }points.readpointsUpdate
useSafeArea(){ top, bottom, left, right }nonenativeReady

usePoints() needs points.read for its first read through getPoints(). The pointsUpdate event itself needs no permission.

  • Every hook is safe outside the app. It returns defaults ('light', 'vi', null, zero insets).
  • Replies that arrive after unmount, or after a newer value, are ignored.
  • useUser() and usePoints() trigger the permission prompt on mount the first time. Mount them where asking makes sense to the user.
import { usePoints } from '@i-catholic/mini-app-sdk/react'

function PointsBadge() {
const { points } = usePoints()
return <span>{points ?? '–'} điểm</span>
}