Skip to content

Quickstart

Installation

yarn add redux-agent

Or:

npm i redux-agent

TypeScript definitions are included.

Adding to your project

Import the agents near to where the store is configured:

  import { createStore } from 'redux'
+ import { configureAgents, createHttpAgent } from 'redux-agent'
  import reducer from './reducers'

  const store = createStore(reducer)

+ store.subscribe(configureAgents([ createHttpAgent() ], store))

Import the helpers in your reducer:

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

  const reducer = (state, action) => {
    switch(action.type) {

Concatenate your reducer with taskReducer:

    }
  }

- export default reducer
+ export default reduceReducers(reducer, taskReducer)

That’s all. Now you can create tasks and drive effects from the reducer:

  switch(action.type) {
    case 'FETCH_TODO':
      return addTask({ 
        type: 'http', 
        method: 'get', 
        url: 'https://jsonplaceholder.typicode.com/todos/1',
        actions: { 
          success: 'FETCH_TODO_SUCCESS',
          failure: 'FETCH_TODO_FAILURE'
        }
      })

Next steps