gpt4 book ai didi

reactjs - ReactJS 中的非标准自定义属性?

转载 作者:行者123 更新时间:2023-12-05 09:21:03 28 4
gpt4 key购买 nike

这是关于非标准属性的。 https://facebook.github.io/react/docs/tags-and-attributes.html

在 react 中我做了这个:

 React.createElement('div', {image:'blah', etc:'blah'});

我需要使用 setAttribute 在元素上设置 imageetc,我需要使用react以使用它的智能来维护它它改变了。

这里有一个解决方案 https://stackoverflow.com/a/21654914/1828637说要在 componentDidMount 上添加它,但这不是解决方案。该属性不会被维护,因为它会被 React 框架更改。

有没有办法告诉 React 在我的自定义标签上设置属性?

最佳答案

在 React 中,现在可以使用 16 个自定义属性

// Your code:
<div mycustomattribute="something" />

// React 15 output:
<div />

// React 16 output:
<div mycustomattribute="something" />

react 16 custom attributes

关于reactjs - ReactJS 中的非标准自定义属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34914976/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com