【问题标题】:Show id or name attribute in the dom element which is created by React Native在 React Native 创建的 dom 元素中显示 id 或 name 属性
【发布时间】:2021-01-05 19:19:54
【问题描述】:

我正在使用 react native web 并在与 3rd 方工具集成时发现该工具需要 Id 属性或 Name 属性才能运行。有没有办法实现以下目标?

例如: 在 React Native 中

<TextInput id="text-input" ... > ... </TextInput>

浏览器中的预期输出

<input id='text-input' ... />

【问题讨论】:

    标签: reactjs react-native react-native-web


    【解决方案1】:

    在浏览了 React Native 文档后,我找到了实现这一点的方法。 React Native 允许使用 setNativeProps 来操作组件。

    可以在here找到相关文档。

    【讨论】:

      【解决方案2】:

      为了保持与 ReactNative 的兼容性,RNW 使用 nativeID 这是在文档中的 here

      所以要在 React Native Web 中的视图上设置一个 ID,它将映射到元素 dom 节点这样做

      <View nativeID="some-id" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-16
        • 2021-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-28
        • 1970-01-01
        相关资源
        最近更新 更多