Since you are using thegetElementsByClassNamemethod, it will return an array/collection containing the elements of the given class.
If you only have one element, use.querySelectorinstead.
Alternatively, if you prefer to use thegetElementsByClassNamemethod, you can use a for loop or the.find()method to find the desired element and apply the style.
In React, I think usingrefis better than using the DOM API to locate elements.
Since you are using the
getElementsByClassName
method, it will return an array/collection containing the elements of the given class.If you only have one element, use
.querySelector
instead.Alternatively, if you prefer to use the
getElementsByClassName
method, you can use a for loop or the.find()
method to find the desired element and apply the style.In React, I think using
ref
is better than using the DOM API to locate elements.