4 回答

TA貢獻1815條經驗 獲得超13個贊
您需要將 props 傳遞給組件,如下所示:
const helloElement = <CComponent classname='xyz' content='helloWorld' />

TA貢獻1847條經驗 獲得超11個贊
您將作為孩子傳遞您的值,要將值作為道具傳遞,您可以這樣做:<CComponent classname='xyz' content='helloWorld' />

TA貢獻1777條經驗 獲得超3個贊
根據反應文檔:
React.createElement(
type,
[props],
[...children]
)
<CComponent>{{ classname: "xyz", content: "helloWorld" }}</CComponent>這是由 babel 編譯為:
var helloElement = React.createElement(CComponent, null, {
classname: 'xyz',
content: 'helloWorld'
})
但<CComponent classname='xyz' content='helloWorld' />
被編譯為
var helloElement= React.createElement(CComponent, {
classname: "xyz",
content: "helloWorld"
})
因此在 UI 上呈現

TA貢獻1804條經驗 獲得超7個贊
使用 babel 7 和 React >= 16 是行不通的。CComponent 獲取帶有 {classname,content} 對象的 Children 屬性。
您可以嘗試稍微更改一下語法,它將完美呈現
<CComponent {...{ className: "xyz", content: "helloWorld" }} />
添加回答
舉報