简体   繁体   English

如何在 React 中通过 ID="" 选择 React 组件(不使用 ref)

[英]How to select a React Component by ID="" in React (without using ref)

I am importing SVG elements into React component, and then rendering them as components.我将 SVG 元素导入 React 组件,然后将它们渲染为组件。

How do I attach a reference to React Components that contain SVG elements from within my componentDidMount()?如何从我的 componentDidMount() 中附加对包含 SVG 元素的 React 组件的引用?

Well, i don't see code example.好吧,我没有看到代码示例。 U can try to use jQuery, when your component render will finish - this is magic stick in many situations.你可以尝试使用 jQuery,当你的组件渲染完成时 - 这在许多情况下都是魔术棒。 Just type smth like:只需键入 smth,例如:

let element = $('#element_id');

And you will get access to its information您将可以访问其信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM