Skip to content

Commit

Permalink
docs(cn): useRecoilStateLoadable translation (#78)
Browse files Browse the repository at this point in the history
* docs(cn): useRecoilStateLoadable translation

* docs(cn): add suggestions from review

Co-authored-by: Kim Yang <Kim.Yang.GH@outlook.com>

* docs(cn): fix spacing issue

Co-authored-by: Kim Yang <Kim.Yang.GH@outlook.com>
  • Loading branch information
KnowsCount and KimYangOfCat authored May 10, 2021
1 parent 147d4f3 commit 3a5f20a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/docs/api-reference/core/useRecoilStateLoadable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(state: RecoilState<T>): [Loadable<T>, (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}) {
Expand Down

0 comments on commit 3a5f20a

Please sign in to comment.