
获得徽章 0
- react 性能优化要点:
1. 数组遍历给定唯一的 key,最好不要是索引(index)。
2. 使用 immutable 定制 react 组件shouldComponentUpdate 生命周期,管理 state 对象和 store 可以减少不必要的渲染。(React.PureComponent 与 React.memo 都是浅对比)
immutable使用:github.com
3. 使用 reselect 避免冗余的计算。
reselect 使用:github.com
4. 服务端渲染 / 预渲染
框架 Next.js:nextjs.org
5. 异步组件 / 组件懒加载
6. 提取 CSS,静态资源合并、压缩加 hash,利用浏览器缓存机制
具体优化分析可以使用 React Developer Tools 、Chrome DevTools 等工具。
上述只是一些思路,具体原因和实现细节,不妨你亲自研究实现一下-。-展开等人赞过评论11