Skip to main content


Selectors are used to select a specific piece of state.

Reactive Select

We can select state with The select method returns an Observable which emits when the selected state changes.

select takes a callback function which gives access to the current global state:

import { Observable } from 'rxjs';
import { TodoState } from './todo-reducer';

const globalState$: Observable<any> = => state);
const todoState$: Observable<TodoState> = => state['todo']);

Memoized Selectors

MiniRx comes with memoized selectors out of the box. With the selectors we can easily select and combine state. The MiniRx selectors are memoized to prevent unnecessary calculations.


createFeatureStateSelector selects a feature state from the global state object. We have to use the same key that we used for registering the feature reducer (e.g. we used the 'todo' key for the todoReducer).

import { createFeatureStateSelector } from 'mini-rx-store';
import { TodoState } from './todo-reducer';

export const getTodoFeatureState = createFeatureStateSelector<TodoState>('todo');


With createSelector we can require many other selectors to create a new selector. The last argument passed to createSelector is the projection function. In the projection function we can access the return values of the required selectors.

import { createSelector } from 'mini-rx-store'

export const getTodos = createSelector(
state => state.todos

export const getSelectedTodoId = createSelector(
state => state.selectedTodoId

export const getSelectedTodo = createSelector(
(todos, id) => todos.find(item => === id)

Let's use the memoized selectors to create our state Observables:

import { getTodoFeatureState, getTodos, getTodosCount } from './todo-selectors';

const todoState$: Observable<TodoState> =;
const todos$: Observable<Todo[]> =;
const selectedTodo$: Observable<Todo> =;