Bruinen
Bruinen

Reputation: 109

Selecting multiple DOM elements in React

I made simple React component with some images that I want to animate as they are shown in viewport. To use getboundingclientrect() method I have to pass an element so I used js querySelectorAll('img') in componentDidMount() where my scrollEventListener is. It doesn't feel like the right way to go (although works fine). Is there more 'Reactish' solve for that problem?

Upvotes: 0

Views: 932

Answers (1)

ChrisR
ChrisR

Reputation: 4008

Yes, you need to use Refs.

With React, usually you shouldn't have to use native dom selectors. By using refs it stays in the React scope and you'll have a more robust workflow.

Upvotes: 1

Related Questions