JSX是一种在React中使用的、JS的语法扩展格式,它是接近JS的、但非标准的JS语法。
如果想要在JS环境执行(比如浏览器),或者想对其进行混淆加密以提升代码安全性,就需要将JSC转化成标准JS代码。
那么,如何将JSX转JS呢?
当然是使用工具啦,比如JShaman的JSX转JS工具:
![]()
例,JSX代码:
function Greeting({ name }) { return (
Hello, {name}!h1>Welcome to our website.p> alert('Clicked!')}> Click Me button> div> );}
转化成JS会得到:
function Greeting({ name }) { return /*#__PURE__*/( React.createElement("div", { className: "greeting" }, /*#__PURE__*/ React.createElement("h1", null, "Hello, ", name, "!"), /*#__PURE__*/ React.createElement("p", null, "Welcome to our website."), /*#__PURE__*/ React.createElement("button", { onClick: () => alert('Clicked!') }, "Click Me" ) ));}
有需要的朋友,快去使用吧。
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.