Skip to content
Advertisement

how i get querySelectorAll html elements in react?

I am using react with functional component. I also use react-bootstrap , I attached the react-bootstrap carousel , everything is fine with react-bootstrap, for some functionality, I want to get three divs in react , divs has same classes. I know if I use simple html css js then I easily do that,

querySelectorAll(".indicator-btn")

but i want this on react. How can I do that? please suggest me a best practices for that.

This is a my component , in the last i have three divs which i want for Dom.

JavaScript

Advertisement

Answer

You could use useState to get its refs (also useRef but there’ll be a lot more inconveniences potentially).

JavaScript

At some point (after 1st rendering) you’ll have btn1, btn2, btn3 as button elements. If you want to use it, assumingly imperatively, you could useEffect

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement