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 Introduction to React Native Implementing React Native Containers, Components, and Styles

Confused about handleSubmit method

In the React Native course, the instructor uses a handleSubmit method in both the container and the component. I'm trying to figure out how this works. Thanks!

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

These are two separate functions in two different classes, although the function in the parent container is passed into the passed into the child component. Data doesn't normally get passed from child to parent in React but the data from the component needs to get to the Redux container to change state (this gets filled out in the next stage of the course). So we pass down a function to call when a submit happens that takes the data the container wants as an argument. The component's handleSubmit() is called when the button is pressed, which in turn calls the function supplied through props by the parent.

Cristina Rosales
Cristina Rosales
10,929 Points

So...its basically like a 'ref' in regular ReactJS?