React — Input Data Binding
Drop-Downs
Dropdowns is a common form input control element added to many apps. It’s the select element in HTML. In React, we have to set the value attribute of the select element to the value we selected in addition to adding the onChange
handler to add a handler to get the selected value and set it as the state.
For instance, we write the following code to do that:
Cascading dropdowns in React JS
Step 1 : Take a list of states and cities object related to every state or we can get this data using apis.
Step 2 : Loop over the states data to show dropdown related to All States.
Step 3 : Now save the selected state.
Step 4 : Based on selected state value , get the corresponding cities and show them in dropdown as follows :
import { useState } from "react";