react-demo's People
react-demo's Issues
Redux使用指南
-
调用
- store.getState(): state包含所有combineReducers()方法涵盖的reducer
- store.dispatch(): 传入action对象或创建函数
- action会广播当前的action对象给所有reducer
- reducer根据action.type返回新的state,实现更新
-
ATTENTION && TIPS
- 同一个操作引起的多种更新:利用不同的reducer处理同一个类型的action。参照popup reducer
- 不能直接mutate state来返回新的state,用对象的扩展运算或Object.assign({}, state, action.value);
使用PureComponent + 重组state避免非必要render
为了避免state的改变导致的不必要的render,针对比较复杂的情况,shouldComponentUpdate()的实现逻辑比较麻烦。此时,可以考虑使用PureComponent并重组state结构。
把所有不需要导致组件re-render的属性组织为一个对象,然后将这个对象作为state的属性。同时,组件继承PureComponent,这样React在对state进行比较的时候使用的是浅比较。需要注意的是,更新这些属性的时候必须用mutate的方式,React浅比较时才会认为这个state没有变化。
具体的实现参照ScrollPage组件,_handleScroll()方法。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.