# 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 http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava3/subscribeAsState.composable#(io.reactivex.rxjava3.core.Completable).subscribeAsState()()` Subscribes to this `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Flowable.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava3/subscribeAsState.composable#(io.reactivex.rxjava3.core.Flowable).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Maybe.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava3/subscribeAsState.composable#(io.reactivex.rxjava3.core.Maybe).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava3/subscribeAsState.composable#(io.reactivex.rxjava3.core.Observable).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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> http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/rxjava3/subscribeAsState.composable#(io.reactivex.rxjava3.core.Single).subscribeAsState(kotlin.Any)(initial: R)` Subscribes to this `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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-rxjava3](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava3/RxJava3Adapter.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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` and represents its completed state via `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`. Once the `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html#onErrorComplete--` or `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html#onErrorResumeNext-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.rxjava3.core.CompletableSource&gt;-`.

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

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

### Flowable.subscribeAsState

Artifact: [androidx.compose.runtime:runtime-rxjava3](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava3/RxJava3Adapter.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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Flowable.html#onErrorReturn-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Flowable.html#onErrorResumeNext-io.reactivex.rxjava3.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.rxjava3.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-rxjava3](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava3/RxJava3Adapter.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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Maybe.html#onErrorComplete--`, `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Maybe.html#onErrorReturn-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Maybe.html#onErrorResumeNext-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.rxjava3.core.MaybeSource&lt;? extends T&gt;&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava3.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-rxjava3](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava3/RxJava3Adapter.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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html#onErrorReturn-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends T&gt;-` or `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html#onErrorResumeNext-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.rxjava3.core.ObservableSource&lt;? extends T&gt;&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava3.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-rxjava3](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/rxjava3/RxJava3Adapter.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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/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 `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html#onErrorReturn-io.reactivex.rxjava3.functions.Function&lt;java.lang.Throwable,? extends T&gt;-` or `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html#onErrorResumeNext-io.reactivex.rxjava3.functions.Function&lt;? super java.lang.Throwable,? extends io.reactivex.rxjava3.core.SingleSource&lt;? extends T&gt;&gt;-`.

```kotlin
import androidx.compose.material.Text
import androidx.compose.runtime.rxjava3.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 |