transform-react-jsx 中的 "pragma h" 是什么?
What is "pragma h" in transform-react-jsx?
我在这里遇到了这个配置https://github.com/developit/zero-to-preact/blob/master/webpack.config.js
plugins: [
['transform-react-jsx', { pragma: 'h' }]
]
文档说
pragma
string, defaults to React.createElement.
Replace the function used when compiling JSX expressions.
Note that the @jsx React.DOM pragma has been deprecated as of React v0.12
但不知道 'h' 是什么意思!这是什么?
默认情况下,babel 等会将 <div id="hello" />
转换为 React.createElement("div", { id: "hello" });
。 pragma: h
将改为生成,如 h("div", { id: "hello" });
.
React.createElement
(或 Preact 的 h
)是构建虚拟 DOM.
的函数
我在这里遇到了这个配置https://github.com/developit/zero-to-preact/blob/master/webpack.config.js
plugins: [
['transform-react-jsx', { pragma: 'h' }]
]
文档说
pragma
string, defaults to React.createElement.
Replace the function used when compiling JSX expressions.
Note that the @jsx React.DOM pragma has been deprecated as of React v0.12
但不知道 'h' 是什么意思!这是什么?
默认情况下,babel 等会将 <div id="hello" />
转换为 React.createElement("div", { id: "hello" });
。 pragma: h
将改为生成,如 h("div", { id: "hello" });
.
React.createElement
(或 Preact 的 h
)是构建虚拟 DOM.