Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In React do ref's reference the virtual DOM, or the actual DOM?

I'm assuming the virtual DOM, and that React takes care of it with diff'ing. But I had a recruiter say that ref's affect the actual DOM, I can't see how this can be. I assume that they were just mistaken.

like image 393
bcourtney5965 Avatar asked Sep 06 '25 11:09

bcourtney5965


1 Answers

Refs should reference the actual DOM. One usage of Refs is integrating with third-party DOM libraries, so you can directly modify the DOM using Refs. If Refs reference the virtual DOM, I don't think the demand can be meet. You modify a virtual DOM, but you can't make sure the modification would be synchronized to the actual DOM. Besides, if you want to modify actual DOM when using react, you should always modify the state of components instead of modifying the DOM by Refs.

like image 180
Jason Xu Avatar answered Sep 09 '25 05:09

Jason Xu