---
title: "rememberTextFieldState"
description: "Create and remember a [TextFieldState]. The state is remembered using [rememberSaveable] and so
will be saved and restored with the composition.

If you need to store a [TextFieldState] in another object, use the [TextFieldState.Saver] object
to manually save and restore the state."
type: "composable"
---

<div class='type'>Composable Function</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
fun rememberTextFieldState(
    initialText: String = "",
    initialSelection: TextRange = TextRange(initialText.length),
): TextFieldState
```


Create and remember a `TextFieldState`. The state is remembered using `rememberSaveable` and so
will be saved and restored with the composition.

If you need to store a `TextFieldState` in another object, use the `TextFieldState.Saver` object
to manually save and restore the state.

#### Parameters

| | |
| --- | --- |
| initialText | The initial text state. If a different value is passed in a subsequent recomposition, the value of the state will _not_ be updated. To update the state after it's initialized, call methods on `TextFieldState`. |
| initialSelection | The initial selection state. If a different value is passed in a subsequent recomposition, the value of the state will _not_ be updated. To update the state after it's initialized, call methods on `TextFieldState`. |





