Help to understand why the state of the store does not accumulate. I'm doing a twitter-like app. In the store I want to add posts. And the store constantly resets its state. I do not think where you need to correct the code. After all, they write in the official docks: (previousState, action) => newState, although the store there is stored in an array, and not in a literal like mine: http://redux.js.org/docs/basics/Reducers.html

My application is entirely here: https://github.com/SkunSHD/redux-twitter-like-app/tree/master

The reducer code looks like this: reducers / page.js

import { ADD_POST, ADD_COMMENT, LOGIN_SUCCES } from '../constants/Page' const initialState = { user: '', text: '' } export default function page(state = initialState, action) { switch (action.type) { case LOGIN_SUCCES: return { ...state, user: action.payload } case ADD_POST: return { ...state, user: state.user, text: action.payload } case ADD_COMMENT: return { ...state, user: action.payload.user, text: action.payload.text } default: return state; } } 

actions / PageActions:

 import { ADD_POST, ADD_COMMENT } from '../constants/Page' export function addPost(text) { return (dispatch) => { dispatch({ type: ADD_POST, payload: text }) } } 

    1 answer 1

    In a reducer, here in this place:

     case ADD_POST: return { ...state, user: state.user, text: action.payload } 

    you change the state, state.text becomes equal to action.payload, i.e. the text that you add via the addPost function. In order for the old values ​​to remain, it is necessary to add and not to overwrite, for example:

      return { ...state, user: state.user, text: state.text + action.payload }