JSX

最后更新于:2022-04-02 03:33:28

[TOC] > [教程](https://zh-hans.reactjs.org/docs/introducing-jsx.html) ## 插入变量 ``` const name = 'Josh Perez'; const element =

Hello, {name}

; ReactDOM.render( element, document.getElementById('root') ); ``` ## 插入函数 ``` function formatName(user) { return user.firstName + ' ' + user.lastName; } const user = { firstName: 'Harper', lastName: 'Perez' }; const element = (

Hello, {formatName(user)}!

); ReactDOM.render( element, document.getElementById('root') ); ``` ### JSX 特定属性 用大括号包裹 js代码 `const element = ; `
';