GithubHelp home page GithubHelp logo

my-redux-demo's Introduction

#redux + react-router + react es6 1 npm install

2 npm start

3 打开浏览器 localhost:3000

redux原理

1 reducer(在reduxAdd.js中的方法)会初始化一个状态 就是state={a:1}

2 当我们调用其中的方法的时候 也即是在我们的index.js中

store.dispatch({type: 'ADD',count: 2});

注意我们首先注入的是

import reducer from './reduxAdd'

const store=createStore(reducer);

所以我们可以对应的使用 store.dipatch({type: 'ADD',count: 2}) 也就是我们的reduxAdd.js中暴露出来的方法

3 为什么我在组件One中改变a的值在组件DecreaseOne中也会重新渲染 这就是redux的亮点之处 其实就是一个全局变量 但是会重新渲染所有组件

加入react-router实现两个页面的轮换,并且我们的redux中的a是公用的 点击+-仍然会在另一个里面变化

第一页

第二页

my-redux-demo's People

Contributors

33033624 avatar zhangtiantian10 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.