React 使用经验
硬性要求
- 通过数组渲染元素 必须使用数据的唯一标志
- 判断数据是否有值 一律使用
lodash
的isUndefined
或者 与undefined
比较
推荐
- 写页面时 不要使用 PureComponent
- 返回 Promise 的方法 使用 async
- 属性在使用的时候给默认值或者检查; 在传递时不需要使用;
- 属性只有和后台交互相关的数据需要给默认值;
- 其他情况下 不要给默认值,
- 比如 自己定义的方法, 其他三方库的属性或方法
- 例: react-redux 的 dispatch, react-router 的 history location, antd 表单 的 form 等;
一般
经验
- shouldComponentUpdate(nextProps, nextState, nextLegacyContext) 第三个context需要注意
网友评论