---
title: "mutableStateMapOf"
description: "Create a instance of [MutableMap]<K, V> that is observable and can be snapshot."
type: "function"
---

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


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
@StateFactoryMarker
public fun <K, V> mutableStateMapOf(): SnapshotStateMap<K, V>
```


Create a instance of `MutableMap`<K, V> that is observable and can be snapshot.



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


```kotlin
@StateFactoryMarker
public fun <K, V> mutableStateMapOf(vararg pairs: Pair<K, V>): SnapshotStateMap<K, V>
```


Create a instance of `MutableMap`<K, V> that is observable and can be snapshot.



## Code Examples
### stateMapSample
```kotlin
fun stateMapSample() {
    @Composable
    fun NamesAndAges() {
        var name by remember { mutableStateOf("name") }
        var saying by remember { mutableStateOf("saying") }
        val sayings = remember {
            mutableStateMapOf(
                "Caesar" to "Et tu, Brute?",
                "Hamlet" to "To be or not to be",
                "Richard III" to "My kingdom for a horse",
            )
        }
        Column {
            Row {
                BasicTextField(value = name, onValueChange = { name = it })
                BasicTextField(value = saying, onValueChange = { saying = it })
                Button(onClick = { sayings[name] = saying }) { Text("Add") }
                Button(onClick = { sayings.remove(name) }) { Text("Remove") }
            }
            Text("Sayings:")
            Column {
                for (entry in sayings) {
                    Text("${entry.key} says '${entry.value}'")
                }
            }
        }
    }
}
```

