# computedMediaQuery

> Evaluates a query against the current [UiMediaScope], wrapped in a [computedStateOf].

## API Reference

### computedMediaQuery

> Source set: Common

```kotlin
@Composable
public fun <T> computedMediaQuery(query: UiMediaScope.() -> T): State<T>
```

Evaluates a query against the current [UiMediaScope](https://composables.com/jetpack-compose/androidx.compose.ui/ui/interfaces/UiMediaScope/api.md), wrapped in a `computedStateOf`.

Use this function for queries that involve frequently changing values, such as
`UiMediaScope.windowWidth` or `UiMediaScope.windowHeight`. It ensures that compositions only
recompose when the result of the `query` changes, not on every small change to the underlying
values (like a 1px size change).

For queries on stable properties, you can use the simpler [mediaQuery](https://composables.com/jetpack-compose/androidx.compose.ui/ui/composable-functions/mediaQuery/api.md) function.

#### Parameters

| | |
| --- | --- |
| query | The condition to evaluate against the [UiMediaScope](https://composables.com/jetpack-compose/androidx.compose.ui/ui/interfaces/UiMediaScope/api.md). |

#### Return

A [State](https://composables.com/jetpack-compose/androidx.compose.runtime/runtime/interfaces/State/api.md) holding the result of the query. The state will only update when the evaluated result of the query changes.

## Code Examples

### ComputedMediaQuerySample

```kotlin
@Sampled
@Composable
fun ComputedMediaQuerySample() {
    Box(Modifier.fillMaxSize().padding(top = 100.dp)) {
        val showDualPane by computedMediaQuery { windowWidth >= 600.dp }
        val showNavigationRail by computedMediaQuery {
            windowWidth >= 500.dp && viewingDistance != ViewingDistance.Near
        }

        Column(Modifier.fillMaxSize()) {
            Row(Modifier.weight(1f).fillMaxWidth()) {
                if (showNavigationRail) {
                    // Show navigation rail
                    Box(Modifier.width(150.dp).background(Color.Red).fillMaxHeight())
                }

                // Actual content
                Box(Modifier.weight(1f).background(Color.Yellow).fillMaxHeight())

                if (showDualPane) {
                    // Split screen into 2 panes for additional content
                    Box(Modifier.weight(1f).background(Color.Cyan).fillMaxHeight())
                }
            }

            if (!showNavigationRail && !showDualPane) {
                // Show bottom navigation
                Box(Modifier.background(Color.Blue).height(80.dp).fillMaxWidth())
            }
        }
    }
}
```
