Redux - PatrickRBailey/ReactNativeTutorialWork GitHub Wiki

Guides

https://lorenstewart.me/2016/11/27/a-practical-guide-to-redux/

Notes

Action -> Reducer -> State

Action

An action is a plain javascript object that must define a type property.

Reducer

A Reducer takes an action and changes the state based on the action

State

The data source of the application

Sample Redux Code

const reducer = (state = [], action) => {
	if (action.type === 'split_string') {
    return action.payload.split('');
  }
  else if (action.type === 'add_char') {
		return [ ...state, action.payload ];
  }
  
  return state;
};

const store = Redux.createStore(reducer);

store.getState();

const action = {
  type: 'split_string',
  payload: 'asdf'
};

store.dispatch(action);

store.getState();

const action2 = {
  type: 'add_char',
  payload: 'a'
};

store.dispatch(action2);
store.getState();