18910140161

JavaScript-从标准HTML-Stack溢出向react组件传递道具

顺晟科技

2022-10-19 14:00:36

110

所以我想实现一种东西,我可以在HTML元素中放置自定义属性,这些属性将被react组件作为道具。类似于:

function someFunction(props) {
    return <h1>props.something</h1>
}

HTML:

function someFunction(props) {
    return <h1>props.something</h1>
}

呈现:

function someFunction(props) {
    return <h1>props.something</h1>
}

我认为这样的方法可以奏效,但我不认为这是最好的方法

function someFunction(props) {
    return <h1>props.something</h1>
}

我是新手,所以请帮助我:)

ps:我正在使用打字脚本


顺晟科技:

在HTML元素上设置的每个属性都可以在属性中使用。但是请记住,有一个从dash样式到camelcase的命名转换(请参见mdn).

您应该能够执行以下操作:

function someFunction(props) {
    return <h1>props.something</h1>
}
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航