Lib que gerencia uma State previsível e imutável
Single Source of Truth
State is read-only
Changes are made with pure functions
Talk-driven development State Container previsível, facil de entender Inspirado no Flux sem a complexidadeUma intenção de mudar o state. Único caminho para a store.
let nextVampireId = 0; export const ADD_VAMPIRE = 'ADD_VAMPIRE'; /* Action Creator */ export function addVampire(vamp) { /* Action */ return { type: ADD_VAMPIRE, payload: { id: nextVampireId++, name: vamp } }; }
<button onClick={dispatch(addVampire('Tiago'))}>Add Vampire</button>Actions are payloads of information that send data from your application to your store. They are the only source of information for the store. You send them to the store using store.dispatch().
Altera o state pelas Actions
import { ADD_VAMPIRE } from './vampires.js'; export default function vampires(state = [], action) { switch (action.type) { case ADD_VAMPIRE: const { id, name } = action.payload; return [ ...state, { id, name } ] default: return state; } }
import { createStore, combineReducers } from 'redux'; import { vampires } from './reducers.js'; let store = createStore(combineReducers({ vampires })); /* { vampires: [] } */ store.dispatch(addVampire('Temer')); /* { vampires: [{ id: 1, name: 'Temer'}] } */
React Conf: Hot Reloading with Time Travel