Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Components 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.