Course contentsShow
← React Native
Lesson 182 of 1,5553. Core Primitive ComponentsFree lesson

Managing Input Ref Chains

Learners will pass focus control between sequential fields for streamlined form filling.

Managing Input Ref Chains

In this lesson, you will learn how to improve user experience by automatically shifting the keyboard focus from one text input to the next as a user completes their entry.

When building forms, forcing a user to manually tap the next field after typing is a friction point that slows down data entry. To create a "chain," we use the useRef hook to create pointers to our TextInput components, allowing us to programmatically trigger the .focus() method on the next field when the current one is finished.

Building the Chain

First, create a reference for each TextInput using useRef. Then, provide an onSubmitEditing prop to your components. This prop fires when the user taps the "Next" or "Done" button on their soft keyboard. Within that function, we simply call .focus() on the reference of the field we want to jump to.

import React, { useRef } from 'react';
import { TextInput } from 'react-native';

const Form = () => {
  const emailRef = useRef(null);
  const passwordRef = useRef(null);

  return (
    <>
      <TextInput
        placeholder="Email"
        returnKeyType="next"
        onSubmitEditing={() => passwordRef.current.focus()}
      />
      <TextInput
        ref={passwordRef}
        placeholder="Password"
        returnKeyType="done"
      />
    </>
  );
};

Why This Matters

By setting returnKeyType="next" on intermediate fields, the keyboard itself changes to provide a "Next" button. When the user taps it, the onSubmitEditing callback executes, instantly highlighting the next field and keeping the keyboard open. This creates a seamless flow that makes long forms feel significantly shorter and more professional.

Remember, you must assign the ref prop to the specific TextInput component you intend to jump to. If you leave the ref blank or point it to the wrong component, the focus command will fail, and the user will be stuck on their current field.

Key Takeaway: Use useRef to store references for your input fields and trigger .focus() within the onSubmitEditing event to create a frictionless, keyboard-driven navigation flow.