|
@ -34,6 +34,8 @@ If you use React on the web, you'll also need the same version of [ReactDOM](/ap |
|
|
|
|
|
|
|
|
## Exports {/*exports*/} |
|
|
## Exports {/*exports*/} |
|
|
|
|
|
|
|
|
|
|
|
### State {/*state*/} |
|
|
|
|
|
|
|
|
<YouWillLearnCard title="useState" path="/apis/usestate"> |
|
|
<YouWillLearnCard title="useState" path="/apis/usestate"> |
|
|
|
|
|
|
|
|
Declares a state variable. |
|
|
Declares a state variable. |
|
@ -46,6 +48,34 @@ function MyComponent() { |
|
|
|
|
|
|
|
|
</YouWillLearnCard> |
|
|
</YouWillLearnCard> |
|
|
|
|
|
|
|
|
|
|
|
<YouWillLearnCard title="useReducer" path="/apis/usereducer"> |
|
|
|
|
|
|
|
|
|
|
|
Declares a state variable managed with a reducer. |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
function MyComponent() { |
|
|
|
|
|
const [state, dispatch] = useReducer(reducer, { age: 42 }); |
|
|
|
|
|
// ... |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
</YouWillLearnCard> |
|
|
|
|
|
|
|
|
|
|
|
### Context {/*context*/} |
|
|
|
|
|
|
|
|
|
|
|
<YouWillLearnCard title="useContext" path="/apis/usecontext"> |
|
|
|
|
|
|
|
|
|
|
|
Reads and subscribes to a context. |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
function MyComponent() { |
|
|
|
|
|
const theme = useContext(ThemeContext); |
|
|
|
|
|
// ... |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
</YouWillLearnCard> |
|
|
|
|
|
|
|
|
|
|
|
### Refs {/*refs*/} |
|
|
|
|
|
|
|
|
<YouWillLearnCard title="useRef" path="/apis/useref"> |
|
|
<YouWillLearnCard title="useRef" path="/apis/useref"> |
|
|
|
|
|
|
|
|
Declares a ref. |
|
|
Declares a ref. |
|
|