# BlocSelector

### BlocSelector with automatically retrieved Bloc

#### with selector function

```kotlin
@Composable
inline fun <reified BlocA: BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState : Any>
BlocSelector(
    blocTag:String?=null,
    crossinline selectorFn: @DisallowComposableCalls (BlocAState)->BlockSelectedState,
    content:@Composable (BlockSelectedState)->Unit
    )
```

#### with AbstractSelector

```kotlin
@Composable
inline fun <reified BlocA: BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState : Any>
 BlocSelector(
    blocTag:String?=null,
    selector:AbstractSelector<BlocAState,BlockSelectedState>,
    content:@Composable (BlockSelectedState)->Unit
    )
```

`BlocSelector` is analogous to [BlocBuilder ](https://beyondeye.gitbook.io/compose-bloc/bloc-documentation/blocs-and-compose-overview/blocbuilder)but allows to select parts of the full Bloc state, or in general some value derived from one or more fields of the full Bloc state.&#x20;

This is the value that will be passed to the `content` composable, and recomposition will be triggered not by change of the full bloc state but instead of this derived value.

An optional blocTag parameter can be specified in order to identify a specific bloc instance in the case where there is more than one instance of a bloc of the same type registered for the current composable subtree (see [BlocProvider](https://beyondeye.gitbook.io/compose-bloc/bloc-documentation/blocs-and-compose-overview/blocprovider))

The `blocTag` parameter is not present in the original `flutter_bloc` implementation.

For selecting part of the original Bloc state, it is possible to use a selector function `selectorFn`&#x20;

or an [`AbstractSelector`](https://beyondeye.gitbook.io/compose-bloc/bloc-documentation/blocs-and-compose-overview/selectorfor)

### BlocSelector for externally provided Bloc

#### with selector function

```kotlin
@Composable
inline fun <reified BlocA:BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState:Any>
BlocSelector(
    externallyProvidedBlock:BlocA,
    crossinline selectorFn:@DisallowComposableCalls (BlocAState)->BlockSelectedState,
    content:@Composable (BlockSelectedState)->Unit
    )
```

#### with AbstractSelector

```kotlin
@Composable
inline fun <reified BlocA:BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState:Any>
BlocSelector(
    externallyProvidedBlock:BlocA,
    selector:AbstractSelector<BlocAState,BlockSelectedState>,
    content:@Composable (BlockSelectedState)->Unit
    )
```

These are the same as the previous methods but with an  explicitly specified Bloc instance `externallyProvidedBlock` , not retrieved implicitly from current registered blocs in the current composable subtree.

&#x20;Use this method if for example you have retrieved the Bloc already with [`rememberProvidedBlocOf` ](https://beyondeye.gitbook.io/compose-bloc/bloc-documentation/blocprovider#rememberprovidedblocof)
