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

react-native-web-hooks

> 前端框架
开源

适用于 React Native Web 和 Expo 的钩子

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

适用于 React Native Web 和 Expo 的钩子

react-native-web-hooks

Hooks for implementing complex functionality in React Native for web and Expo.

A closer look at how the hooks work here.

Installation

bash
yarn add react-native-web-hooks

or

npm install --save react-native-web-hooks

Usage - Hooks

Import the library into your JavaScript file:

javascript
import {
  useDimensions,
  useActive,
  useFocus,
  useHover,
  useREM,
  useScaledSize,
} from 'react-native-web-hooks';

Get REM size

Use these in place of rem font sizes like: font-size: 1.3rem.

Note: this isn't a hook anymore and will be moved out in the future.

javascript
const fontSize = useREM(1.3);

return ;

Get scaled font size

These change based on the width of the screen.

javascript
const fontSize = useScaledSize(1.5);

return ;

Get dimensions

Note that fontScale is hard-coded to 1 on the react-native-web side and shouldn't be used to calculate dynamic font sizes.

javascript
const {
  window: { width, height, fontScale, scale },
  screen,
} = useDimensions();

Measure a view

It's best to style a view based on that own view's size and not the window size. To make this easier you can use the useLayout hook!

Using onLayout may require you to install resize-observer-polyfill. Learn more in the official Expo docs

javascript
const {
  onLayout,
  width,
  height,
  x,
  y
} = useLayout();

return 

Create pseudo class styles

These will be replaced by React Flare when it's released.

…

Usage - Render Props

Import the library into your JavaScript file:

javascript
import { Hoverable, Resizable } from 'react-native-web-hooks';

You can wrap a function or a component.

typescript
import React, { Component } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { Hoverable } from 'react-native-web-hooks';

const createLogger = (...msg) => () => {
  console.log(...msg);
};

class App extends Component {
  render() {
    return (
      
        
          {isHovered => (
            
              Welcome to React}
            
          )}
        
      
    );
  }
}

Observe window resize events.

typescript
return (
  
    {layout => }
  
);

Issues· 9 开放

查看全部 Issues在 GitHub 打开

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

> 标签

TypeScripthooksreactreact-nativereact-native-web

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

> 工具信息

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

> 相关工具

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