question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to assign a ref to UI component?

See original GitHub issue

Trying to refactor a component to a contained/pure pair. This is a web RTC component, so at some point I need to attach audio/video streams to <video/> elements contained in the UI. In order to keep the component pure, this needs to be done in the container logic.

Is there any way to render the UI component with a known, fixed ref? Then I could call this.refs.ui.refs.localVideo or this.refs.ui.refs.remoteVideo to get access to the contained video elements. I recognize this is ugly, but the only other way I can think to do this is to assign ids to the video elements, and that’s even uglier. 😃 Open to any other suggestions on how the container component can access elements in the UI component. I can almost guarantee the UI component will be mounted and visible at the point where the elements need to be accessed, so I’m not concerned about it not being available at time of use.

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
minfawangcommented, Jun 13, 2016
0reactions
clayne11commented, Jun 22, 2016

PR is done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >
Forwarding Refs - React
We create a React ref by calling React.createRef and assign it to a ref variable. We pass our ref down to <FancyButton ref={ref}>...
Read more >
Using refs in React functional components (part 1) - useRef + ...
Refs are simply references to anything, like a DOM node, Javascript value, etc. To create a ref in a functional component we use...
Read more >
Typescript/React: How can a ref be added to a material-ui Box ...
1 Answer 1 · How can a ref be added to a Box component? #19284 · [Box] Allow ref on Box #19275 ·...
Read more >
React Ref: A Complete Guide with Examples - CopyCat Blog
React provides a feature known as refs that allow for DOM access from components. You simply attach a React ref to an element...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found