D
D
Denis2019-08-15 21:26:16
JavaScript
Denis, 2019-08-15 21:26:16

How to bind input values ​​in React?

In the second step of the form validation, there are two inputs: Cities and Countries.
It is necessary that when one of the Countries is selected, the cities of the selected country are displayed
Link to the project
https://codesandbox.io/s/form-task-oryj0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-08-15
@fristyr

getCitiesOptions = () => {
  const country = +this.state.country;

  return Object.entries(cities)
    .filter(n => n[1].country === country)
    .map(([ id, city ]) => (
      <option key={id} value={id}>
        {city.name}
      </option>
    ));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question