facebook react redux code example

Example 1: what is redux

What is Redux?

Redux is a pattern and library for managing and updating application state, 
using events called "actions". It serves as a centralized store for state 
that needs to be used across your entire application, with rules ensuring 
that the state can only be updated in a predictable fashion.

Example 2: Redux

npm install redux // adding redux to the project
// creating types 
export const SET_USER = 'SET_USER'
//creating actions 
export const setUser = user => {
  return {
    type : SET_USER,
    payload : {
      currentUser : user
    }
  }
// creating reducers 
  const user_reducer = (state=intialState,action)=>{
    switch(action.type){
      case SET_USER :
        return {
          currentUser : action.payload.currentUser
        }
    }