Coder Social home page Coder Social logo

react-demo's Introduction

to-do 进阶

理解UI更新条件! 组件的state或者props改变!

最原始

  • 组件自己管理数据和逻辑
  • 手动setState修改组件内部状态更新UI

使用store

  • 数据管理放在store,组件内引入全局store
  • 逻辑操作在组件内定义方法,调用store派发action, 更新store的数据
  • 订阅store的改变同步更新到组件state,store.subscribe(this.handleStoreChange),函数体this.setState(store.getState())

缺点:组件内部要处理逻辑,显式引入store,和订阅store状态变更的回调更新组件内部state再重新render显得不优雅

react-redux 引入容器组件

  • 组件定义为UI组件,不处理逻辑
  • 不显式引入store,使用react-redux的connect方法,将store中的state和派发action的相关逻辑注入到UI组件中,组件内部通过this.props获取这些数据和方法, 最后被包装成容器组件,对外暴露。
  • store数据改变,导致props改变,所以组件刷新
  • 依赖注入的设计**

优点:UI和逻辑分离

react-demo's People

Contributors

firenzia avatar

Watchers

 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.