Rangle.io: React Training
master
master
  • Rangle React Training Materials
  • lessons
    • redux-hello
    • react-summary
    • redux-action-reducer
    • react-outline
    • react-container
    • redux-intro
    • redux-connect
    • react-component
    • advanced
    • redux-store
    • redux-logging
    • redux-thunk
    • react-cardlist
    • redux-merge
    • react-lifecycles
    • react-intro
  • CONDUCT
  • misc
    • summary
    • refs
    • overview
    • guide
    • gloss
  • LICENSE
  • index
  • rough-slides
    • react-training-slides
  • CONTRIBUTING
Powered by GitBook
On this page
  • The State Problem
  • What is Redux
  • Three Principles
  • How Redux Works
  • Actions
  • Reducer
  • Store
  • Getting Redux
  • Redux DevTools

Was this helpful?

  1. lessons

redux-intro

The State Problem

  • Applications are becoming more complex

  • GUI applications have many different points of interaction, leading to different sources of state updates

  • Web applications have to reconcile state between client and server

  • Asynchronous nature of JavaScript and server-side calls introduces additional points of failure

  • Server side rendering, caching, and distributed data add more complexity

What is Redux

Redux is a predictable state container for JavaScript apps.

  • A framework for managing state

  • Streamlines state interactions using a common pattern

  • Removes two-way interaction in favor of a uni-directional data flow

Three Principles

  • A single source of truth

  • State is read-only

  • State is updated using pure functions

How Redux Works

![Redux Flow]()

Actions

  • The sole mechanism for inducing changes in state

  • Application dispatches actions whenever an event happens

    • E.g., button clicked, page has finished loading, AJAX call has returned data

  • Actions contain:

    • Something that identifies the change

    • Any additional information needed to update the state

Reducer

  • The method by which state is actually changed

  • Takes the "before" state and the action and returns the "after" state

  • Follows the same data flow as the general programming concept of a "reducer"

Store

  • Where the entire application state exists

  • An application should only have one store

  • In larger applications, the store will have several parts

    • Partitioning state is a key architectural decision

Getting Redux

  • Redux is available via NPM

    • npm install redux

  • There is also a package that provides easy interoperability between Redux and React called react-redux

    • npm install react-redux

    • Makes integration easier but is not absolutely necessary

Redux DevTools

    • Visualize your application's current state

    • Move forward and backwards throughout your state (time travelling!)

  • Available for Chrome, Firefox and Electron and other environments

Previousreact-containerNextredux-connect

Last updated 5 years ago

Was this helpful?

FIXME: replace with a Rangle version

is a debugging tool that allows you to:

this diagram
Redux DevTools