diff --git a/docs/docs/api.en-US.md b/docs/docs/api.en-US.md index 9acb65e936..2fdaba0450 100644 --- a/docs/docs/api.en-US.md +++ b/docs/docs/api.en-US.md @@ -9,7 +9,7 @@ This is ahooks API specification document. Hooks are allowed to have no output, which is generally common in life cycle Hooks. ```javascript -useMount(()=>{}); +useMount(() => {}); ``` ### 2. value type @@ -19,6 +19,7 @@ Hooks have one output value. ```javascript const documentVisibility = useDocumentVisibility(); ``` + ### 3. value setValue type The output is value and setValue, the structure is `[value, setValue]` 。 @@ -37,11 +38,12 @@ const [current, { inc, dec, set, reset }] = useCounter(...); ### 5. values type -The output is multi-value type, the structure is `{...values}`  +The output is multi-value type, the structure is `{...values}` ```javascript const {text, left, right, ...} = useTextSelection(); ``` + ### 6. values actions type The output is multi-value and multi-actions type, the structure is `{...values, ...actions}` 。 @@ -50,7 +52,6 @@ The output is multi-value and multi-actions type, the structure is `{...values, const {data, error, loading, run} = useRequest(...); ``` - ## Parameter In principle, more than two parameters are not allowed. @@ -70,12 +71,13 @@ Direct input regardless of whether a single parameter is required. ```javascript const size = useSize(dom); ``` + ### 3. Multiple required parameters The number of required parameters is less than 2, and should be input at the same level. ```javascript -const ref = useKeyPress(keyFilter, eventHandler) +const ref = useKeyPress(keyFilter, eventHandler); ``` If there are more than two, they should be entered as an object. @@ -101,5 +103,3 @@ Required parameters are before and non-required parameters are after. ```javascript const result = useTextSelection(items, defaultSelected?); ``` - - diff --git a/docs/docs/api.zh-CN.md b/docs/docs/api.zh-CN.md index 457e7a0098..d98cc51108 100644 --- a/docs/docs/api.zh-CN.md +++ b/docs/docs/api.zh-CN.md @@ -9,7 +9,7 @@ 允许 Hooks 无输出,一般常见于生命周期类 Hooks。 ```javascript -useMount(()=>{}); +useMount(() => {}); ``` ### 2. value 型 @@ -19,6 +19,7 @@ Hooks 输出仅有一个值。 ```javascript const documentVisibility = useDocumentVisibility(); ``` + ### 3. value setValue 型 输出值为 value 和 setValue 类型的,结构为 `[value, setValue]` 。 @@ -34,13 +35,15 @@ const [state, setState] = useLocalStorageState(...) ```javascript const [current, { inc, dec, set, reset }] = useCounter(...); ``` + ### 5. values 型 -输出值为多 value 类型的,结构为 `{...values}`  +输出值为多 value 类型的,结构为 `{...values}` ```javascript const {text, left, right, ...} = useTextSelection(); ``` + ### 6. values actions 型 输出值为多 value 与多 actions 类型的,结构为 `{...values, ...actions}` 。 @@ -49,7 +52,6 @@ const {text, left, right, ...} = useTextSelection(); const {data, error, loading, run} = useRequest(...); ``` - ## 参数 原则上不允许超过两个参数。 @@ -69,12 +71,13 @@ const documentVisibility = useDocumentVisibility(); ```javascript const size = useSize(dom); ``` + ### 3. 多必选参数 必选参数小于 2 个,应平级输入。 ```javascript -const ref = useKeyPress(keyFilter, eventHandler) +const ref = useKeyPress(keyFilter, eventHandler); ``` 如果多于 2 个,应以 object 形式输入。 @@ -100,5 +103,3 @@ const result = useRequest(service, { ```javascript const result = useTextSelection(items, defaultSelected?); ``` - - diff --git a/packages/hooks/src/useEventTarget/demo/demo2.tsx b/packages/hooks/src/useEventTarget/demo/demo2.tsx index 180162578b..2c6475233c 100644 --- a/packages/hooks/src/useEventTarget/demo/demo2.tsx +++ b/packages/hooks/src/useEventTarget/demo/demo2.tsx @@ -20,7 +20,7 @@ export default () => { value={value} onChange={onChange} style={{ width: 200, marginRight: 20 }} - placeholder="请输入" + placeholder="Please type here" /> + {visible && } ); diff --git a/packages/hooks/src/useSafeState/index.en-US.md b/packages/hooks/src/useSafeState/index.en-US.md index 3754cde0e8..e93d5d9f5c 100644 --- a/packages/hooks/src/useSafeState/index.en-US.md +++ b/packages/hooks/src/useSafeState/index.en-US.md @@ -10,7 +10,7 @@ group: # useSafeState -It is exactly the same with useState, but after the component is unmount, the setState is no longer executed to avoid memory leakage. +It is exactly the same with `React.useState` , but after the component is unmounted, the `setState` in the asynchronous callback will no longer be executed to avoid memory leakage caused by updating the state after the component is unmounted. ## Examples diff --git a/packages/hooks/src/useSafeState/index.zh-CN.md b/packages/hooks/src/useSafeState/index.zh-CN.md index 968d94c8e4..d6b8519bc0 100644 --- a/packages/hooks/src/useSafeState/index.zh-CN.md +++ b/packages/hooks/src/useSafeState/index.zh-CN.md @@ -10,7 +10,7 @@ group: # useSafeState -用法与 useState 完全一样,但是在组件卸载后 setState 不再执行,避免因组件卸载后更新状态而导致的内存泄漏。 +用法与 `React.useState` 完全一样,但是在组件卸载后异步回调内的 `setState` 不再执行,避免因组件卸载后更新状态而导致的内存泄漏。 ## 代码演示