Skip to content

Commit b978cf5

Browse files
committed
docs: zh support
1 parent ba3e7bc commit b978cf5

34 files changed

+1182
-4
lines changed

.changeset/slick-heads-send.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@lynx-js/react-use": patch
33
---
44

5-
Introduce `useVelocity`.
5+
Introduce `useVelocity`: a hook that tracks touch velocity and direction with smoothing support.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<br />
2626
A React-style hooks library designed specifically for <a href="https://lynxjs.org/react/">ReactLynx</a>.
2727
<br />
28-
Bringing familiar React patterns to cross-platform applications.
28+
Translations: <a href="https://github.com/lynx-community/reactlynx-use/blob/main/README.zh-CN.md">🇨🇳 汉语</a>
2929
</sup>
3030
<br />
3131
<br />
@@ -62,6 +62,7 @@
6262
- [**MainThreadScripts**](./docs/en/mts/README.md)
6363
- [`useMainThreadImperativeHandle`](./docs/en/mts/useMainThreadImperativeHandle.md) &mdash; main-thread version of React's [useImperativeHandle](https://react.dev/reference/react/useImperativeHandle).
6464
- [`useTapLock`](./docs/en/mts/useTapLock.md) &mdash; a hook for locking tap events.
65+
- [`useVelocity`](./docs/en/mts/useVelocity.md) &mdash; a hook that tracks touch velocity and direction with smoothing support.
6566
<br/>
6667
<br/>
6768
- [**Lifecycles**](./docs/en/lifecycles/README.md)

README.zh-CN.md

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,120 @@
1-
TODO
1+
<div align="center">
2+
<h1>
3+
<br/>
4+
<br/>
5+
🐈‍⬛
6+
<br />
7+
<br />
8+
<br />
9+
<br />
10+
<br />
11+
</h1>
12+
<sup>
13+
<br />
14+
<br />
15+
<a href="https://www.npmjs.com/package/@lynx-js/react-use">
16+
<img src="https://img.shields.io/npm/v/@lynx-js/react-use.svg" alt="npm package" />
17+
</a>
18+
<a href="https://www.npmjs.com/package/@lynx-js/react-use">
19+
<img src="https://img.shields.io/npm/dm/@lynx-js/react-use.svg" alt="npm downloads" />
20+
</a>
21+
<a href="./LICENSE">
22+
<img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="license" />
23+
</a>
24+
<br />
25+
<br />
26+
专为 <a href="https://lynxjs.org/react/">ReactLynx</a> 设计的 React 风格 hooks 库。
27+
<br />
28+
</sup>
29+
<br />
30+
<br />
31+
<br />
32+
<br />
33+
<pre>npm i <a href="https://www.npmjs.com/package/@lynx-js/react-use">@lynx-js/react-use</a></pre>
34+
<br />
35+
<br />
36+
<br />
37+
<br />
38+
<br />
39+
</div>
40+
41+
---
42+
43+
<div align="center">
44+
<h2>✨ 特性</h2>
45+
</div>
46+
47+
<br/>
48+
49+
- 🎯 **ReactLynx 兼容** &mdash; 与 ReactLynx 应用无缝集成
50+
- ⚛️ **React 风格 API** &mdash; 为 React 开发者提供熟悉的 hooks API
51+
- 🔧 **跨平台特性** &mdash; 基于 Lynx 跨平台特性精心设计
52+
53+
<br/>
54+
<br/>
55+
56+
---
57+
58+
<div align="center">
59+
<h2>📄 文档</h2>
60+
</div>
61+
62+
- [**主线程脚本**](./docs/zh/mts/README.md)
63+
- [`useMainThreadImperativeHandle`](./docs/zh/mts/useMainThreadImperativeHandle.md) &mdash; React [useImperativeHandle](https://react.dev/reference/react/useImperativeHandle) 的主线程版本。
64+
- [`useTapLock`](./docs/zh/mts/useTapLock.md) &mdash; 用于锁定点击事件的 hook。
65+
- [`useVelocity`](./docs/zh/mts/useVelocity.md) &mdash; 用于跟踪 tap 速度和方向的 hook。
66+
<br/>
67+
<br/>
68+
- [**生命周期**](./docs/zh/lifecycles/README.md)
69+
- [`useEffectOnce`](./docs/zh/lifecycles/useEffectOnce.md) &mdash; 仅运行一次的 [`useEffect`](https://reactjs.org/docs/hooks-reference.html#useeffect)
70+
- [`useLifecycles`](./docs/zh/lifecycles/useLifecycles.md) &mdash; 调用 `mount``unmount` 回调。
71+
- [`useMountedState`](./docs/zh/lifecycles/useMountedState.md)[`useUnmountPromise`](./docs/zh/lifecycles/useUnmountPromise.md) &mdash; 跟踪组件是否已挂载。
72+
- [`useUnmount`](./docs/zh/lifecycles/useUnmount.md) &mdash; 调用 `unmount` 回调。
73+
- [`useUpdateEffect`](./docs/zh/lifecycles/useUpdateEffect.md) &mdash; 仅在更新时运行 `effect`
74+
<br/>
75+
<br/>
76+
- [**副作用**](./docs/zh/side-effects/README.md)
77+
- [`useDebounce`](./docs/zh/side-effects/useDebounce.md) &mdash; 对函数进行防抖处理。
78+
- [`useError`](./docs/zh/side-effects/useError.md) &mdash; 错误分发器。
79+
- [`useThrottle``useThrottleFn`](./docs/zh/side-effects/useThrottle.md) &mdash; 对函数进行节流处理。
80+
<br/>
81+
<br/>
82+
- [**状态**](./docs/zh/state/README.md)
83+
- [`createMemo`](./docs/zh/state/createMemo.md) &mdash; memoized hooks 的工厂函数。
84+
- [`useToggle``useBoolean`](./docs/zh/state/useToggle.md) &mdash; 跟踪布尔值的状态。
85+
- [`useCounter``useNumber`](./docs/zh/state/useCounter.md) &mdash; 跟踪数字的状态。
86+
- [`useDefault`](./docs/zh/state/useDefault.md) &mdash; 当状态为 `null``undefined` 时返回默认值。
87+
- [`useLatest`](./docs/zh/state/useLatest.md) &mdash; 返回最新的 state 或 props
88+
- [`useMap`](./docs/zh/state/useMap.md) &mdash; 跟踪对象的状态。
89+
- [`usePrevious`](./docs/zh/state/usePrevious.md) &mdash; 返回之前的 state 或 props。
90+
- [`useQueue`](./docs/zh/state/useQueue.md) &mdash; 实现简单的队列。
91+
- [`useSet`](./docs/zh/state/useSet.md) &mdash; 跟踪 Set 的状态。
92+
- [`useSetState`](./docs/zh/state/useSetState.md) &mdash; 创建类似 `this.setState` 工作方式的 `setState` 方法。
93+
94+
<br />
95+
<br />
96+
97+
---
98+
99+
<div align="center">
100+
<h2>🙏 致谢</h2>
101+
</div>
102+
103+
<br />
104+
105+
本库中的许多 hooks 都建立在 [**react-use**](https://github.com/streamich/react-use) 提供的优秀基础之上。我们向维护者和贡献者致以诚挚的谢意,感谢他们在 React hooks 生态系统中的杰出工作。
106+
107+
我们还从其他优秀项目中汲取灵感:
108+
109+
- [kripod/react-hooks](https://github.com/kripod/react-hooks)
110+
- [vueuse/vueuse](https://github.com/vueuse/vueuse)
111+
- [alibaba/hooks](https://github.com/alibaba/hooks)
112+
113+
<br />
114+
<br />
115+
116+
---
117+
118+
<p align="center">
119+
用 ❤️ 为 ReactLynx 社区打造
120+
</p>

docs/en/mts/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# Main Thread Script (MTS)
1+
# Main Thread Script (MTS)
2+
3+
_"MTS Hooks"_ unleash the power of Lynx's [Main Thread Script](https://lynxjs.org/next/react/main-thread-script.html).

docs/en/mts/useVelocity.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# useVelocity
2+
3+
A hook that tracks touch velocity and direction with smoothing support.
4+
5+
## Usage
6+
7+
```tsx
8+
import { useVelocity } from "@lynx-js/react-use";
9+
10+
const Demo = () => {
11+
const { getVelocity, handleTouchStartMT, handleTouchMoveMT } = useVelocity({
12+
smoothingFactor: 0.2,
13+
maxTimeDelta: 100,
14+
RTL: false,
15+
});
16+
17+
return (
18+
<view
19+
onTouchStart={handleTouchStartMT}
20+
onTouchMove={handleTouchMoveMT}
21+
onTouchEnd={() => {
22+
const { velocity, direction } = getVelocity();
23+
console.log(`Velocity: ${velocity}px/s, Direction: ${direction}`);
24+
}}
25+
>
26+
<text>Swipe me!</text>
27+
</view>
28+
);
29+
};
30+
```
31+
32+
## Type Declarations
33+
34+
```ts
35+
import type { MainThread } from '@lynx-js/types';
36+
export type Direction = 'forward' | 'backward' | 'none';
37+
export interface UseVelocityOptions {
38+
RTL?: boolean;
39+
smoothingFactor?: number;
40+
maxTimeDelta?: number;
41+
}
42+
export interface VelocityResult {
43+
velocity: number;
44+
direction: Direction;
45+
}
46+
export interface UseVelocityReturn {
47+
getVelocity: () => VelocityResult;
48+
handleTouchStartMT: (event: MainThread.TouchEvent) => void;
49+
handleTouchMoveMT: (event: MainThread.TouchEvent) => void;
50+
}
51+
export default function useVelocity(options?: UseVelocityOptions): UseVelocityReturn;
52+
```

docs/zh/lifecycles/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Lifecycle
2+
3+
> **致谢:** 部分文档基于 [react-use](https://github.com/streamich/react-use/blob/master/docs/Lifecycles.md)
4+
5+
_"Lifecycle Hooks"_ modify and extend built-in React hooks or imitate React Class component lifecycle patterns.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# useEffectOnce
2+
3+
> **致谢:** Re-export from [react-use](https://github.com/streamich/react-use)
4+
5+
仅运行一次的 [`useEffect`](https://reactjs.org/docs/hooks-reference.html#useeffect)
6+
7+
## 示例
8+
9+
```tsx
10+
import { useEffectOnce } from "@lynx-js/react-use";
11+
12+
const Demo = () => {
13+
useEffectOnce(() => {
14+
console.log("Running effect once on mount");
15+
16+
return () => {
17+
console.log("Running clean-up of effect on unmount");
18+
};
19+
});
20+
21+
return null;
22+
};
23+
```
24+
25+
## 类型定义
26+
27+
```ts
28+
import type { EffectCallback } from "@lynx-js/react";
29+
30+
declare const useEffectOnce: (effect: EffectCallback) => void;
31+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# useLifecycles
2+
3+
> **致谢:** Re-export from [react-use](https://github.com/streamich/react-use)
4+
5+
React 生命周期 Hook,用于在组件挂载时调用 `mount` 回调,在组件卸载时调用 `unmount` 回调
6+
7+
## 示例
8+
9+
```tsx
10+
import { useLifecycles } from "@lynx-js/react-use";
11+
12+
const Demo = () => {
13+
useLifecycles(
14+
() => console.log("MOUNTED"),
15+
() => console.log("UNMOUNTED")
16+
);
17+
return null;
18+
};
19+
```
20+
21+
## 类型定义
22+
23+
```ts
24+
declare const useLifecycles: (mount: any, unmount?: any) => void;
25+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# useMountedState
2+
3+
> **致谢:** Re-export from [react-use](https://github.com/streamich/react-use)
4+
5+
> **注意!**:尽管名称中包含 `State`,但**_此 Hook 不会导致组件重新渲染_**
6+
> 此组件旨在用于避免在已卸载的组件上更新状态。
7+
8+
生命周期 Hook,提供检查组件挂载状态的能力。
9+
返回一个函数,如果组件已挂载则返回 `true`,否则返回 `false`
10+
11+
## 示例
12+
13+
```tsx
14+
import { useEffect } from "@lynx-js/react";
15+
import { useMountedState } from "@lynx-js/react-use";
16+
17+
const Demo = () => {
18+
const isMounted = useMountedState();
19+
20+
useEffect(() => {
21+
setTimeout(() => {
22+
if (isMounted()) {
23+
// ...
24+
} else {
25+
// ...
26+
}
27+
}, 1000);
28+
});
29+
};
30+
```
31+
32+
## 类型定义
33+
34+
```ts
35+
function useMountedState(): () => boolean;
36+
```

docs/zh/lifecycles/useUnmount.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# useUnmount
2+
3+
> **致谢:** Re-export from [react-use](https://github.com/streamich/react-use)
4+
5+
React 生命周期 Hook,在组件即将卸载时调用一个函数。如果你需要同时使用挂载和卸载函数,请使用 `useLifecycles`
6+
7+
## 示例
8+
9+
```tsx
10+
import { useUnmount } from "@lynx-js/react-use";
11+
12+
const Demo = () => {
13+
useUnmount(() => {
14+
console.log("UNMOUNTED");
15+
});
16+
return null;
17+
};
18+
```
19+
20+
## 类型定义
21+
22+
```ts
23+
declare const useUnmount: (fn: () => any) => void;
24+
```

0 commit comments

Comments
 (0)