From 3a5f20a22e1f9e868023c92afdf60ae1a3995025 Mon Sep 17 00:00:00 2001 From: KnowsCount <56480008+KnowsCount@users.noreply.github.com> Date: Mon, 10 May 2021 20:55:33 +0800 Subject: [PATCH] docs(cn): useRecoilStateLoadable translation (#78) * docs(cn): useRecoilStateLoadable translation * docs(cn): add suggestions from review Co-authored-by: Kim Yang * docs(cn): fix spacing issue Co-authored-by: Kim Yang --- .../api-reference/core/useRecoilStateLoadable.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/docs/api-reference/core/useRecoilStateLoadable.md b/docs/docs/api-reference/core/useRecoilStateLoadable.md index a1fdb8af..8ddc6111 100644 --- a/docs/docs/api-reference/core/useRecoilStateLoadable.md +++ b/docs/docs/api-reference/core/useRecoilStateLoadable.md @@ -3,25 +3,25 @@ title: useRecoilStateLoadable(state) sidebar_label: useRecoilStateLoadable() --- -This hook is intended to be used for reading the value of asynchronous selectors. This hook will implicitly subscribe the component to the given state. +此钩子可用于读取异步 selector 的值。为获取到指定状态值,此钩子将隐含地订阅对应组件。 -Unlike [`useRecoilState()`](/docs/api-reference/core/useRecoilState), this hook will not throw an `Error` or `Promise` when reading from an asynchronous selector (for the purpose of working alongside [React Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)). Instead, this hook returns a [`Loadable`](/docs/api-reference/core/Loadable) object for the value along with the setter callback. +与 [`useRecoilState()`](/docs/api-reference/core/useRecoilState) 不同,当读取异步 selector 时,这个钩子不会抛出一个 `Error` 或`Promise` (为了能与 [React Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html) 共存)。相反,这个钩子会返回一个 [`Loadable`](/docs/api-reference/core/Loadable) 对象的值以及 setter 回调。 --- ```jsx function useRecoilStateLoadable(state: RecoilState): [Loadable, (T | (T => T)) => void] ``` -- `state`: a writeable [`atom`](/docs/api-reference/core/atom) or [`selector`](/docs/api-reference/core/selector) that _may_ have some asynchronous operations. The status of the returned loadable will depend on the status of the provided state selector. +- `state`: 一个可写的 [`atom`](/docs/api-reference/core/atom) 或 _可能_ 有一些异步操作的 [`selector`](/docs/api-reference/core/selector)。返回的 loadable 的状态将取决于所提供的状态 selector 的状态。 -Returns a [`Loadable`](/docs/api-reference/core/Loadable) for the current state with the interface: +返回一个 [`Loadable`](/docs/api-reference/core/Loadable) 的当前状态与接口: -- `state`: indicates the status of the selector. Possible values are `'hasValue'`, `'hasError'`, `'loading'`. -- `contents`: The value represented by this `Loadable`. If the state is `hasValue`, it is the actual value, if the state is `hasError` it is the `Error` object that was thrown, and if the state is `loading`, then it is a `Promise` of the value. +- `state`: 表示 selector 的状态。可能的值是 `hasValue`、`hasError`、`loading`。 +- `contents`: `Loadable` 所代表的值。如果状态是 `hasValue`,它就是实际的值;如果状态是 `hasError`,它就是被抛出的 `Error` 对象,如果状态是 `loading`,那么它就是 `Promise`。 --- -### Example +### 示例 ```jsx function UserInfo({userID}) {