Skip to content

redux-utilities/redux-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
github-actions
Jul 21, 2024
3fa4c50 · Jul 21, 2024
Jul 21, 2024
Mar 4, 2023
Feb 12, 2023
Jan 22, 2023
Apr 24, 2018
Jan 22, 2023
Apr 24, 2018
Jul 3, 2017
Apr 24, 2018
Mar 4, 2023
Jul 21, 2024
Jul 21, 2024
Jan 22, 2023

Repository files navigation

redux-actions

Build Status codecov npm npm

Flux Standard Action utilities for Redux

Table of Contents

Getting Started

Installation

$ npm install --save redux-actions

or

$ yarn add redux-actions

The npm package provides ES modules that should be compatible with every modern build tooling.

Usage

import { createActions, handleActions, combineActions } from 'redux-actions';

const defaultState = { counter: 10 };

const { increment, decrement } = createActions({
  INCREMENT: (amount = 1) => ({ amount }),
  DECREMENT: (amount = 1) => ({ amount: -amount })
});

const reducer = handleActions(
  {
    [combineActions(increment, decrement)]: (
      state,
      { payload: { amount } }
    ) => {
      return { ...state, counter: state.counter + amount };
    }
  },
  defaultState
);

export default reducer;

See the full API documentation.

Documentation