Passing a parent's ref straight to your <input> hands the parent the whole DOM node. It can restyle it, read its value, or move it, and every caller now depends on your markup.
useImperativeHandle(ref, createHandle, dependencies?) replaces what the parent receives. The child attaches its own useRef to the <input> and gives the parent an object instead:
refis the ref the parent passed. Since React 19 it's an ordinary prop; earlier versions neededforwardRefto receive it.createHandletakes no arguments and returns the handle, usually an object of methods. The node stays in a private ref the parent never sees.dependencieswork like an effect's: when one changes (byObject.is), or if you omit the array, React callscreateHandleagain and assigns the new handle. Methods close over the render that created them, so list every value they read.
Timing. React treats the handle like a layout effect. During the commit it sets ref.current to the handle (or calls a ref callback with it), after the child's own DOM refs are attached and before the parent's layout effects run. On unmount it sets the ref back to null, or runs the cleanup a ref callback returned.
When to use it. Only for imperative actions that props can't express: focusing, scrolling, selecting text, starting an animation, calling a third-party widget's method. The React docs' example of misuse is a Modal exposing { open, close }; take an isOpen prop instead. If the parent only needs to focus a field, exposing just focus keeps the component free to change its markup later. Where focus should go for accessibility, and how to type the handle in TypeScript, are separate questions.