Redux

Redux

  • Getting Started
  • API
  • FAQ
  • Github
  • Need help?

›API Reference

Introduction

  • Getting Started with Redux
  • Installation
  • Motivation
  • Core Concepts
  • Three Principles
  • Prior Art
  • Learning Resources
  • Ecosystem
  • Examples

Basic Tutorial

  • Basic Tutorial: Intro
  • Actions
  • Reducers
  • Store
  • Data flow
  • Usage with React
  • Example: Todo List

Advanced Tutorial

  • Advanced Tutorial: Intro
  • Async Actions
  • Async Flow
  • Middleware
  • Usage with React Router
  • Example: Reddit API
  • Next Steps

Recipes

  • Recipes: Index
  • Configuring Your Store
  • Usage With TypeScript
  • Migrating to Redux
  • Using Object Spread Operator
  • Reducing Boilerplate
  • Server Rendering
  • Writing Tests
  • Computing Derived Data
  • Implementing Undo History
  • Isolating Redux Sub-Apps
  • Using Immutable.JS with Redux
  • Code Splitting
  • Structuring Reducers

    • Structuring Reducers: Intro
    • Prerequisite Concepts
    • Basic Reducer Structure
    • Splitting Reducer Logic
    • Refactoring Reducers Example
    • Using combineReducers
    • Beyond combineReducers
    • Normalizing State Shape
    • Updating Normalized Data
    • Reusing Reducer Logic
    • Immutable Update Patterns
    • Initializing State

FAQ

  • FAQ Index
  • General
  • Reducers
  • Organizing State
  • Store Setup
  • Actions
  • Immutable Data
  • Code Structure
  • Performance
  • Design Decisions
  • React Redux
  • Miscellaneous

Other

  • Glossary
  • Troubleshooting
  • Feedback

API Reference

  • API Reference
  • createStore
  • Store
  • combineReducers
  • applyMiddleware
  • bindActionCreators
  • compose

compose(...functions)

Composes functions from right to left.

This is a functional programming utility, and is included in Redux as a convenience.
You might want to use it to apply several store enhancers in a row.

Arguments

  1. (arguments): The functions to compose. Each function is expected to accept a single parameter. Its return value will be provided as an argument to the function standing to the left, and so on. The exception is the right-most argument which can accept multiple parameters, as it will provide the signature for the resulting composed function.

Returns

(Function): The final function obtained by composing the given functions from right to left.

Example

This example demonstrates how to use compose to enhance a store with applyMiddleware and a few developer tools from the redux-devtools package.

import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import DevTools from './containers/DevTools'
import reducer from '../reducers'

const store = createStore(
  reducer,
  compose(applyMiddleware(thunk), DevTools.instrument())
)

Tips

  • All compose does is let you write deeply nested function transformations without the rightward drift of the code. Don't give it too much credit!
Last updated on 4/2/2021
← bindActionCreators
Redux
Docs
Getting StartedCore ConceptsBasicsAdvanced
Community
Stack OverflowDiscord
More
GitHubStar
Copyright (c) 2015-present Dan Abramov and the Redux documentation authors.
Some icons copyright Font Awesome and Noun Project (Hassan ali, ProSymbols)