How to create dependent dropdowns in React?

Build two dropdowns where the second dropdown’s data updates based on the first dropdown’s selected value.

intermediateForms and inputsreactdropdownstateconditional rendering
Published: 10/26/2025
Updated: 10/26/2025

Question

How to create dependent dropdowns in React?


Answer

Use useState to track selections and dynamically render the second dropdown based on the first selection.

import { useState } from 'react';

function CountryStateDropdown() {
  const countries = {
    India: ['Delhi', 'Mumbai', 'Bangalore'],
    USA: ['New York', 'California', 'Texas'],
  };

  const [country, setCountry] = useState('');
  const [states, setStates] = useState([]);

  const handleCountryChange = (e) => {
    const selected = e.target.value;
    setCountry(selected);
    setStates(countries[selected] || []);
  };

  return (
    <div>
      <select onChange={handleCountryChange}>
        <option value=''>Select Country</option>
        {Object.keys(countries).map((c) => (
          <option key={c}>{c}</option>
        ))}
      </select>

      {states.length > 0 && (
        <select>
          {states.map((s) => (
            <option key={s}>{s}</option>
          ))}
        </select>
      )}
    </div>
  );
}

✅ The second dropdown updates dynamically based on the first selection.

Real-World Example

  • Country → State selection
  • Category → Sub-category filters
  • Car brand → Model lists

Quick Practice

Create three dependent dropdowns (Country → State → City).

Summary

Track selection state and update dependent data dynamically for chained dropdowns.

Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions

Can dropdowns depend on API data?

Yes, fetch the dependent options when the first dropdown changes.


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.