Skip to content

Commit 742d2bf

Browse files
Add use hook API reference page (#6177)
* [WIP] Add use hook API reference page * [WIP] Update use hook API reference page based on feedback * [WIP] use hook API ref doc: add browser API example * [WIP] use hook API ref doc: add context, lib examples * [WIP] use reference doc - incorporate all current feedback * [WIP] use reference page fix typos * use reference doc: address PR feedback from Luna, Sophia,Eli, and Lee * Apply @harish-sethuraman's typo fixes from code review Co-authored-by: Strek <[email protected]> * use reference doc typo fixes * use reference doc: update style to match other react.dev conventions * minor fixes * Remove client Promises, use canary labels * Add use hook section to index, remove RSC section on components page * Final edits * Clarify use reference caveats --------- Co-authored-by: Strek <[email protected]>
1 parent 46e7b2c commit 742d2bf

File tree

3 files changed

+519
-0
lines changed

3 files changed

+519
-0
lines changed

src/content/reference/react/index.md

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ To prioritize rendering, use one of these Hooks:
106106
107107
---
108108
109+
## Resource Hooks {/*resource-hooks*/}
110+
111+
*Resources* can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a context.
112+
113+
To read a value from a resource, use this Hook:
114+
115+
- [`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
116+
117+
```js
118+
function MessageComponent({ messagePromise }) {
119+
const message = use(messagePromise);
120+
const theme = use(ThemeContext);
121+
// ...
122+
}
123+
```
124+
125+
---
126+
109127
## Other Hooks {/*other-hooks*/}
110128
111129
These Hooks are mostly useful to library authors and aren't commonly used in the application code.

0 commit comments

Comments
 (0)