DEV Community

Cover image for React Ref to add className

React Ref to add className

Vinay Veerappaji on October 30, 2020

Hey there React developers! Wanna Know how to add className dynamically with some really cool example? Then you are in right place. Go through th...
Collapse
 
98lenvi profile image
Lenvin Gonsalves

Thanks!

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

Class components 🤮

Collapse
 
vinayveerappaji profile image
Vinay Veerappaji

You can make this in functional component also....

Collapse
 
goran7777 profile image
Goran

This is unusable,i cant add class with refs on socket event at all.I ask myself if we cant add simple class on some socket event ,why refs exists?

Collapse
 
0liviermartinez profile image
Olivier Martinez

Right ??
Vue let's you do that.

this.$refs['some-ref'].$el.classList.add('some-class')