2022-04-06 05:56:08 +00:00
|
|
|
# `useState`
|
|
|
|
|
|
|
|
```ts
|
2022-04-13 17:41:41 +00:00
|
|
|
useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
|
2022-04-06 05:56:08 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
* **key**: A unique key ensuring that data fetching can be properly de-duplicated across requests
|
2022-04-13 17:41:41 +00:00
|
|
|
* **init**: A function that provides initial value for the state when it's not initiated. This function can also return a `Ref`.
|
2022-04-06 05:56:08 +00:00
|
|
|
* **T**: (typescript only) Specify the type of state
|
|
|
|
|
|
|
|
::ReadMore{link="/guide/features/state-management"}
|
|
|
|
::
|