# Coming from Jetpack Compose (https://crow.build/docs/from-compose)

If you already know Jetpack Compose, you can read and write Crow in minutes. Crow intentionally keeps Compose's authoring vocabulary (`Column`, `Row`, `Box`, `Modifier`, `LazyColumn`, `MaterialTheme`) while replacing the execution model underneath.

## The One Mental-Model Shift [#the-one-mental-model-shift]

In Jetpack Compose, a `@Composable` function is a **template that re-executes** whenever state it reads changes. Every `remember`, `derivedStateOf`, `LaunchedEffect`, stability annotation, and deferred-lambda trick exists to work around function re-execution.

In Crow, a `@Ui` function is a **setup block that runs once**.

| Concept | Jetpack Compose | Crow |
| --- | --- | --- |
| Component declaration | `@Composable fun Card(...)` | `@Ui fun Card(...)` |
| Local state | `var n by remember { mutableIntStateOf(0) }` | `var n by signal(0)` |
| Survives process death | `var q by rememberSaveable { mutableStateOf("") }` | `var q by saved("")` |
| Derived state | `val doubled by remember { derivedStateOf { n * 2 } }` | `val doubled by { n * 2 }` |
| Side effects | `LaunchedEffect(key) { ... }` / `DisposableEffect` | `effect({ key }) { v, prev -> onCleanup { ... } }` |
| Conditional UI | Plain `if (cond)` (re-runs whole scope) | Reactive `if (cond)` (lowered to a scoped region) |
| Keyed lists | `items(list, key = { it.id })` / `forEach` | `For(list, key = { it.id })` / `LazyColumn` |
| Static prop hint | `@Immutable` / `@Stable` annotations | `@Once` on props that never change |
| CompositionLocal | `compositionLocalOf { ... }` | `contextOf(...)` (owner-tree scoped) |
| Async loading | Manual `UiState` sealed class + ViewModel | `resource` / `crow-query` + `Loading` / `Errored` |

## Why `remember` Disappears [#why-remember-disappears]

Because `@Ui` functions run once, local variables already live for the lifetime of the component instance. You never wrap signals, controllers, or lambdas in `remember { ... }`.

<Tabs items={["Crow","Jetpack Compose"]}>
<Tab value="Crow">
```kotlin
@Ui
fun SearchBar(@Once onSearch: (String) -> Unit) {
    val query = saved("")
    val trimmed by { query.value.trim() }
    val canSubmit by { trimmed.isNotEmpty() }

    Row(Modifier.fillMaxWidth().padding(16.dp)) {
        OutlinedTextField(
            value = query,
            placeholder = { Text("Search...") },
            modifier = Modifier.weight(1f),
        )
        Button(
            onClick = { onSearch(trimmed) },
            enabled = canSubmit,
        ) {
            Text("Go")
        }
    }
}
```
</Tab>

<Tab value="Jetpack Compose">
```kotlin
@Composable
fun SearchBar(onSearch: (String) -> Unit) {
    var query by rememberSaveable { mutableStateOf("") }
    val trimmed by remember { derivedStateOf { query.trim() } }
    val canSubmit by remember { derivedStateOf { trimmed.isNotEmpty() } }

    Row(Modifier.fillMaxWidth().padding(16.dp)) {
        OutlinedTextField(
            value = query,
            onValueChange = { query = it },
            placeholder = { Text("Search...") },
            modifier = Modifier.weight(1f),
        )
        Button(
            onClick = { onSearch(trimmed) },
            enabled = canSubmit,
        ) {
            Text("Go")
        }
    }
}
```
</Tab>
</Tabs>

## The Compiler Has Your Back [#the-compiler-has-your-back]

The single mistake Compose developers make on day one is writing a plain `val` that reads a signal:

```kotlin
var count by signal(0)
val doubled = count * 2 // ❌ Compile Error CR1001!
```

Because the body runs once, `val doubled = count * 2` would freeze `0` forever. Crow's K2 FIR checker catches this at compile time (`CR1001`) and tells you to write either:

- `val doubled by { count * 2 }` — reactive derived value
- `val initial = untrack { count * 2 }` — explicit one-time snapshot

Similarly, mutating a signal directly inside a `@Ui` body is caught at compile time (`CR1002`).

## Greenfield Android, Native Escape Hatch [#greenfield-android-native-escape-hatch]

Crow is built for greenfield Android apps that want zero recomposition, zero ViewModel ceremony, and zero AndroidX glue. When you need a legacy Android `View` (such as a `WebView`, `SurfaceView`, or third-party SDK view), embed it directly in any Crow layout with `NativeView` from `crow-ui`.