美文网首页
redux基本使用方法

redux基本使用方法

作者: 小梁姐姐 | 来源:发表于2017-12-27 11:21 被阅读0次
  import {createState} from 'redux'


export default function() {
    //定义计算规则。即reducer
    function counter(state= 0, action) {
        switch(action.type){
            case 'INCREMENT':
                return state+1
            case 'DECREMENT':
                return state-1
            default:
                return state
        }
    }

    //根据计算规则生成store
    let store = createState(counter)

    //定义数据(state)变化之后的派发规则
    store.subscribe(() => {
        console.log(store.getState())
    })

    //触发数据变化
    store.dispatch({type: 'INCREMENT'}) //1
    store.dispatch({type: 'INCREMENT'}) //2
    store.dispatch({type: 'DECREMENT'}) //1
}

相关文章

  • redux基本使用方法

  • redux基本的使用方法

    redux使用方法 在看本文章之前,如果对于redux的原理不太熟悉,可以先观看胡子大哈的React小书. 部分原...

  • redux 及 react-redux 的基本使用

    本文介绍 redux 的基本使用,介绍 redux 的流程。以及 react-redux 的基本使用 一、redu...

  • Redux简介

    Redux React-redux React-router Redux 1、基本用法: Redux中存在几个概念...

  • redux基础

    Redux react-redux React-router Redux 1、基本用法: Redux中存在几个概念...

  • redux基本

    Redux核心概念 整个应用的状态(State)都放在Store中,组件每次的重新渲染都必然由状态变化引起 该状态...

  • 7.Redux学习体会

    Redux中文文档: http://www.redux.org.cn/ Redux 入门教程(一):基本用法: h...

  • 玩Android(flutter + fish_redux)

    fish_redux使用 注:该项目为Flutter + fish_redux,页面基本均是fish_redux搭...

  • GitHub Popular App Redux

    目录 什么是Redux Redux 优点 Redux 的三个基本原则 Redux 有那几部分组成 Action r...

  • react-redux中的数据传递

    1、connect connect用于连接React组件与 Redux store,其使用方法如下 [mapSta...

网友评论

      本文标题:redux基本使用方法

      本文链接:https://www.haomeiwen.com/subject/eczygxtx.html