Skip to main content

usePlatform

React hook to tracked the platform of the user.

Usage

Live Editor

function Demo() {
  const {platform} = usePlatform(); 

  return <p>platfrom: {platform}</p>;
};
Result
Loading...

API

UsePlatformProps

PropertyDescriptionTypeDefaultValue
userAgentWhen server rendering, you need to pass userAgentstring-

usePlatform

Returns

UsePlatformReturn: object that related to platform

Arguments

ArgumentDescriptionTypeDefaultValue
props-UsePlatformProps | undefined-

UsePlatformReturn

PropertyDescriptionTypeDefaultValue
platformplatformPlatform (Required)-
isInMiniProgramWhether in mini program() => boolean (Required)-
isInWechatwhether in wechat() => boolean (Required)-
isiPhoneXwhether is iPhoneX() => boolean (Required)-

Platform

export type Platform = "ios" | "android" | "unknown";