Skip to content

Random Number Generator

The RNG task handler allows generating random numbers outside of the reducer, so as not to make the reducer impure.

Task: Default

This task causes a random number to be generated and to be dispatched back to as payload of the prescribe action.

  type: 'rng',
  actions: {
    result: string // action type to dispatch when the number has been generated


Event Type Meta Payload
result none number


Run this example »

import {
  addTask, reduceReducers, taskReducer
} from 'redux-agent'

const reducer = (state, action) => {
  switch (action.type) {
    case 'RANDOM_NUMBER':
      return addTask(state, {
        type: 'rng',
        actions: {
          result: 'RANDOM_NUMBER_RESULT'

      return {
        randomNumber: action.payload

      return state

export default reduceReducers(reducer, taskReducer)