Current section: Imperative Handles 36 exercises
Problem

useImperativeHandle

Loading exercise

Transcript

00:00 Okay, we've got this situation where we have this scrollable view right here and you can scroll to or you can add messages and remove them and it auto scrolls for you, which is cool. So this is a little scrollable component, but we also have this desire to scroll to the top and scroll to the bottom.

00:18 And yeah, those buttons aren't working right now. So your job is to make those buttons work. The problem is that these buttons are rendered outside of the scrollable view. So the scrollable view is responsible for scrolling it to the bottom when you add new messages and stuff.

00:37 You need to talk to that scrollable view yourself so that you can say, hey, I want you to scroll to the top or hey, I want you to scroll to the bottom. So that's what your job is. You're going to be using use imperative handle to make that happen. And in my finished version, I actually don't include the dependency rate.

00:54 You don't have to include a dependency array, but you can if you want to. It does complicate things a little bit, but in this particular instance, you actually don't need it. It's not going to be like suboptimal or anything. It's going to work just fine. So yeah, I think you're ready to go. Let's go.