1、JSX书写技巧
- JSX的常用注释方法:{/* 多行注释 */}
- JSX为了避免和Class 混淆,不能写CSS class,使用className代替
- 字符串解析为html的方法是使用<div dangerouslySetInnerHTML = {{__html:item}}></div> 注意这里是两个{},两个_
- JSX为了避免和JS的for循环混淆,不能写 <lable for="id"></lable>,使用 <lable htmlFor="id"></lable> 代替
2、React快速生成代码插件Simple React Snippets,常用快速生成指令如下:
Snippet | Renders |
imr | Import React |
imrc | Import React / Component |
impt | Import PropTypes |
impc | Import React / PureComponent |
cc | Class Component |
ccc | Class Component With Constructor |
sfc | Stateless Function Component |
cdm | componentDidMount |
cwm | componentWillMount |
cwrp | componentWillReceiveProps |
gds | getDerivedStateFromProps |
scu | shouldComponentUpdate |
cwu | componentWillUpdate |
cdu | componentDidUpdate |
cwu | componentWillUpdate |
cdc | componentDidCatch |
gsbu | getSnapshotBeforeUpdate |
ss | setState |
ssf | Functional setState |
ren | render |
rprop | Render Prop |
hoc | Higher Order Component |