UNPKG

taro-hooks

Version:
33 lines (32 loc) 1.81 kB
import Taro from '@tarojs/taro'; import { getLocation, onLocationChange, offLocationChange, onLocationChangeError, offLocationChangeError } from './utils/index'; import type { PromiseAction, PromiseOptionalAction, PromiseWithoutOptionAction, PromiseParamsAction, ExcludeOption, WithUndefind, Callback } from '../type'; export type GetLocation = typeof getLocation; export type OnLocationChange = typeof onLocationChange; export type OffLocationChange = typeof offLocationChange; export type OnLocationChangeError = typeof onLocationChangeError; export type OffLocationChangeError = typeof offLocationChangeError; export type Option = ExcludeOption<Taro.getLocation.Option>; export type Location = WithUndefind<Taro.getLocation.SuccessCallbackResult>; export type Get = PromiseOptionalAction<Option, Taro.getLocation.SuccessCallbackResult>; export type Choose = PromiseOptionalAction<ExcludeOption<Taro.chooseLocation.Option>, Taro.chooseLocation.SuccessCallbackResult>; export type ChoosePOI = PromiseWithoutOptionAction<Taro.choosePoi.SuccessCallbackResult>; export type Open = PromiseAction<ExcludeOption<Taro.openLocation.Option>>; export type ToggleUpdate = PromiseParamsAction<(onOff?: boolean, background?: boolean) => void>; export type ChangeCallback = Taro.onLocationChange.Callback; export type ChangErrorCallback = Taro.onLocationChangeError.Callback; export type On = (callback: ChangeCallback | ChangErrorCallback, error?: boolean) => void; export type Off = (callback: Callback | ChangErrorCallback, error?: boolean) => void; declare function useLocation(options?: Option): [ Location, { get: Get; choose: Choose; choosePOI: ChoosePOI; open: Open; toggleUpdate: ToggleUpdate; on: On; off: Off; } ]; export default useLocation;