Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Components (2018) React Component Patterns Refs and the DOM

what kind of forms requires internal state? or examples?

in the example it mentions that refs can be used on forms that don't require internal state. but how do you know if does or does not?

1 Answer

From 04:09 in the video, they explain the different times you would want to use one over the other.

I don't think there's anything that would require you to use one over the other. You can probably get to a working state with either approach, but there are certainly cases where one approach will make things simpler than another.

One example given in the video is validation of inputs - where React state and event handler would be simpler.

Another is that you don't want the element to render each time and so improve performance - in this instance you could use a ref.

I think the video does a good job of explaining each, but people are different. You may wish to venture off to a search engine and find articles about React ref, it's use case, and you may find examples that help it sink it.