1. 程式人生 > >react-redux基本使用

react-redux基本使用

react redux 基本使用

  • 圖解:
    技術分享圖片
  • 代碼:
    var createStore = require(‘redux‘).createStore
    var indexStore = createStore(function(state=0,action){
    switch(action.type){
        case 1:
            return ++state
        case 0:
            return --state
        default:
            return state
    }
    })
    indexStore.subscribe(function(){
    console.log(indexStore.getState())
    })
    indexStore.dispatch({type:1})
  • 效果:
    技術分享圖片
  • react-redux基本使用