jsx是一个javasciprt的语法扩展,jsx能够生成React元素,能够更好的藐视ui应该呈现出他应有交互的本质形式。java
你能够安全的在jsx中插入用户输入内容,例如react
const title=response.potentiallyMaliciousInput; const element=<h1>{title}</h1>
React dom在渲染全部输入内容以前默认会进行转义,确保你的应用中不会注入明确编写的内容web
在JSX中你能够在大括号内放置任何有效的javascipt表达式,例如:安全
const name='josh' ReactDom.render( element, document.getElementById("root") )
在编译后,JSX表大会会被转为普通的javascipt函数调用dom
function getGreeting(user){ if(user){ return <h1>hello,{formatName(user)}!</h1>; } return <h1>hello,1</h1> }
Bable 会把jsx转义成一个名为React.createElement()
的函数svg
元素是构成函数