JSX表示在JS代码中写HTML代码,是React声明式的表现
React创建的元素的两种方式:creatElement()方法和JSX
1、使用JSX创建React元素
const title=(<h1>Hello React</h1>)
2、使用ReactDOM.render()方法渲染React元素到页面中
ReactDOM.render(title,document.getElementById('root'))
⚠️注意点:
- React元素的属性名使用驼峰命名法
- 特殊的属性:(html---->React)
class----->className
for----->htmlFor
tabindex----->tabIndex - 没有子节点元素可以使用 />结束
const title=(<h1>Hello React <span /></h1>)
- 推荐使用小括号包裹JSX,从而避免JS中自动插入分号的陷阱