# subscribeAsState

## Functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava2/subscribeAsState.composable#(io.reactivex.Completable).subscribeAsState()()` Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html` and represents its completed state via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, T : R> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava2/subscribeAsState.composable#(io.reactivex.Flowable).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html` and represents its values via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, T : R> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava2/subscribeAsState.composable#(io.reactivex.Maybe).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html` and represents its value via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, T : R> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava2/subscribeAsState.composable#(io.reactivex.Observable).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html` and represents its values via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, T : R> https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava2/subscribeAsState.composable#(io.reactivex.Single).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html` and represents its value via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. |

## Functions

### Completable.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava2](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava2/RxJava2Adapter.kt+function:subscribeAsState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun Completable.subscribeAsState(): State<Boolean>
```

Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html` and represents its completed state via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Once the `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html` will be completed the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` will be updated with `true` value causing recomposition of every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State#value()` usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/plugins/RxJavaPlugins.html#onError-java.lang.Throwable-` logic will be used. To handle the error in a more meaningful way you can use operators like `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html#onErrorComplete--` or `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html#onErrorResumeNext-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.CompletableSource&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val completed by completable.subscribeAsState()
Text("Completable is $completed")
```

### Flowable.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava2](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava2/RxJava2Adapter.kt+function:subscribeAsState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <R : Any?, T : R> Flowable<T>.subscribeAsState(initial: R): State<R>
```

Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html` and represents its values via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Every time there would be new value posted into the `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html` the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` will be updated causing recomposition of every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State#value()` usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/plugins/RxJavaPlugins.html#onError-java.lang.Throwable-` logic will be used. To handle the error in a more meaningful way you can use operators like `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html#onErrorReturn-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html#onErrorResumeNext-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends org.reactivestreams.Publisher&lt;? extends T&gt;&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by flowable.subscribeAsState("initial")
Text("Value is $value")
```

| Parameters |
|---|---|
| `initial: R` | The initial value for the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` which will be asynchronously updated with the real one once we receive it from the stream |

### Maybe.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava2](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava2/RxJava2Adapter.kt+function:subscribeAsState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <R : Any?, T : R> Maybe<T>.subscribeAsState(initial: R): State<R>
```

Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html` and represents its value via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Once the value would be posted into the `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html` the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` will be updated causing recomposition of every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State#value()` usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/plugins/RxJavaPlugins.html#onError-java.lang.Throwable-` logic will be used. To handle the error in a more meaningful way you can use operators like `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html#onErrorComplete--`, `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html#onErrorReturn-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html#onErrorResumeNext-io.reactivex.MaybeSource&lt;? extends T&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by maybe.subscribeAsState("initial")
Text("Value is $value")
```

| Parameters |
|---|---|
| `initial: R` | The initial value for the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` which will be asynchronously updated with the real one once we receive it from the stream |

### Observable.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava2](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava2/RxJava2Adapter.kt+function:subscribeAsState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <R : Any?, T : R> Observable<T>.subscribeAsState(initial: R): State<R>
```

Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html` and represents its values via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Every time there would be new value posted into the `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html` the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` will be updated causing recomposition of every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State#value()` usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/plugins/RxJavaPlugins.html#onError-java.lang.Throwable-` logic will be used. To handle the error in a more meaningful way you can use operators like `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#onErrorReturn-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#onErrorResumeNext-io.reactivex.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.ObservableSource&lt;? extends T&gt;&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by observable.subscribeAsState("initial")
Text("Value is $value")
```

| Parameters |
|---|---|
| `initial: R` | The initial value for the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` which will be asynchronously updated with the real one once we receive it from the stream |

### Single.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava2](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava2/RxJava2Adapter.kt+function:subscribeAsState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
@Composable
fun <R : Any?, T : R> Single<T>.subscribeAsState(initial: R): State<R>
```

Subscribes to this `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html` and represents its value via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Once the value would be posted into the `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html` the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` will be updated causing recomposition of every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State#value()` usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/plugins/RxJavaPlugins.html#onError-java.lang.Throwable-` logic will be used. To handle the error in a more meaningful way you can use operators like `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html#onErrorReturn-io.reactivex.functions.Function&lt;java.lang.Throwable,? extends T&gt;-` or `https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html#onErrorResumeNext-io.reactivex.Single&lt;? extends T&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by single.subscribeAsState("initial")
Text("Value is $value")
```

| Parameters |
|---|---|
| `initial: R` | The initial value for the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` which will be asynchronously updated with the real one once we receive it from the stream |