B
B
balex7772021-10-18 15:59:02
React
balex777, 2021-10-18 15:59:02

How to update State after redux dispatch?

How to update State after redux dispatch?

const onChangeCountry = async (id:string) => {
    const index = countries?.findIndex((arr) => arr.id === Number(id));
    if (countries && !countries[Number(index)].cities) {
      const res = await GeoService.getCities(id, 'ru');
      if (res.success) {
        dispatch(setCities({ index, cities: res.cities }));
      }
    }
    if (countries) setCityList(countries[Number(index)].cities);
  };


After selecting a country in Select, I load cities in redux and try to put cities in State to display in another Select. but it doesn’t work, obviously dispactch doesn’t have time to work, because if you re-select the country, then everything is loaded, what to do?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question