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
|
|
|
```
|
|
|
|
|
2022-04-16 13:53:36 +00:00
|
|
|
* **key**: A unique key ensuring that data fetching is properly de-duplicated across requests
|
|
|
|
* **init**: A function that provides initial value for the state when 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"}
|
|
|
|
::
|