百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

the-platform

> 前端框架
开源

Web 组件。

4.4K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Web 组件。

The Platform

Web API's turned into React Hooks and Suspense-friendly React components. #useThePlatform

Install

Note: React 16.8+ is required for Hooks.

With npm

bash
npm i the-platform --save

Or with yarn

bash
yarn add the-platform

Examples

  • Basics
  • Low Quality Image Placeholder
  • Using <Script> and Stripe Checkout

API

  • Hooks
    • useDeviceMotion()
    • useDeviceOrientation()
    • useGeoPosition()
    • useNetworkStatus()
    • useMedia()
    • useScript()
    • useStylesheet()
    • useWindowScrollPosition()
    • useWindowSize()
  • Components
    • ``
    • <Script>
    • <Video>
    • <Audio>
    • <Preload>
    • <Stylesheet>
  • Authors
  • Inspiration

Hooks

useDeviceMotion()

Detect and retrieve current device Motion.

Returns

DeviceMotionEvent

Example

javascript
import { useDeviceMotion } from 'the-platform';

const Example = () => {
  const { acceleration, rotationRate, interval } = useDeviceMotion();

  // ...
};

useDeviceOrientation()

Detect and retrieve current device orientation.

Returns

DeviceOrientationEvent

Example

javascript
import { useDeviceOrientation } from 'the-platform';

const Example = () => {
  const { alpha, beta, gamma, absolute } = useDeviceOrientation();

  // ...
};

useGeoPosition()

Retrieve Geo position from the browser. This will throw a promise (must use with Suspense).

Arguments

PositionOptions

Returns

Position

Example

javascript
import { useGeoPosition } from 'the-platform';

const Example = () => {
  const {
    coords: { latitude, longitude },
  } = useGeoPosition();

  // ...
};

useNetworkStatus()

Retrieve network status from the browser.

Returns

Object containing:

  • isOnline: boolean: true if the browser has network access. false otherwise.

  • offlineAt?: Date: Date when network connection was lost.

Example

javascript
import { useNetworkStatus } from 'the-platform';

const Example = () => {
  const { isOnline, offlineAt } = useNetworkStatus();

  // ...
};

useMedia()

Arguments

query: string | object: media query string or object (parsed by json2mq). defaultMatches: boolean: a boolean providing a default value for matches

Returns

match: boolean: true if the media query matches, false otherwise.

Example

javascript
import { useMedia } from 'the-platform';

const Example = () => {
  const small = useMedia('(min-width: 400px)');
  const medium = useMedia({ minWidth: 800 });

  // ...
};

useScript()

This will throw a promise (must use with Suspense).

Arguments

Object containing:

  • src: string: The script's URI.
javascript
import { useScript } from 'the-platform';

const Example = () => {
  const _unused = useScript({ src: 'bundle.js' });

  // ...
};

useStylesheet()

This will throw a promise (must use with Suspense).

Arguments

Object containing:

  • href: string: The stylesheet's URI.
  • media?: string: Intended destination media for style information.
javascript
import { useStylesheet } from 'the-platform';

const Example = () => {
  const _unused = useStylesheet({ href: 'normalize.css' });

  // ...
};

useWindowScrollPosition()

Returns

Object containing:

  • x: number: Horizontal scroll in pixels (window.pageXOffset).
  • y: number: Vertical scroll in pixels (window.pageYOffset).

Example

javascript
import { useWindowScrollPosition } from 'the-platform';

const Example = () => {
  const { x, y } = useWindowScrollPosition();

  // ...
};

useWindowSize()

Returns

Object containing:

  • width: Width of browser viewport (window.innerWidth)
  • height: Height of browser viewport (window.innerHeight)

Example

javascript
import { useWindowSize } from 'the-platform';

const Example = () => {
  const { width, height } = useWindowSize();

  // ...
};

Components

``

Props

  • src: string
  • anything else you can pass to an `` tag
javascript
import React from 'react';
import { Img } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

<Script>

Props

  • src: string
  • children?: () => React.ReactNode - This render prop will only execute after the script has loaded.
  • anything else you can pass to a <script> tag
javascript
import React from 'react';
import { Script } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

<Video>

Props

  • src: string
  • anything else you can pass to a <video> tag
javascript
import React from 'react';
import { Video } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

<Audio>

Props

  • src: string
  • anything else you can pass to a <audio> tag
javascript
import React from 'react';
import { Audio } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

<Preload>

Preload a resource with <link rel="preload">. For more information check out MDN or the Google Developer Blog.

Props

  • href: string
  • as: string - resource type
javascript
import React from 'react';
import { Preload, Script } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

<Stylesheet>

Lazy load a stylesheet.

Props

  • href: string
javascript
import React from 'react';
import { Stylesheet } from 'the-platform';

function App() {
  return (
    

  );
}

export default App;

Authors

  • Jared Palmer
  • Jack Cross
  • Nathan Force

Inspiration

  • react-fns
  • AOL.

MIT License

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScripthooksreactreact-hooksreact-suspense

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架