get data from dropdown for dynamic call api

Tags: , ,

So I use redux-hooks for state management, so in my application there is a dropdown, the value will be used to call api dynamically, in the action creator I made it like this

export const getFetchCasesSelectedCountry = (country) => (dispatch) => {
return (
  axios.get(`${country}`).then((result) => {
    let confirmed =;
    let recovered =;
    let death =;

      payload: {
        countryConfirmed: confirmed,
        countryRecovered: recovered,
        countryDeath: death,

but i got this error

how to get the value from the dropdown so that it can be entered into the action creator? is it possible? sorry if my question is hard to understand.


There can be various reasons for 404 issue:

  • it can be networking issue – I mean that requested URL is not accessible from your environment. I see from the code that you doing GET request so to test networking you can just open your browser with the URL that is being used in the action. for example.

  • Code that calls getFetchCasesSelectedCountry provides some weird country value that can result in a 404 error

Nevertheless the code that you’ve posted, does not handle errors that can arise from axios call (404 for example) so your store won’t be aware of errors that can happen, hence component that is connected to the store also won’t be aware of such problems.

From my experience, usual approach to handle such things with redux is to introduce more states, that will store error info:

// this is purely an example
// let say that you have such state
const state = {
    loading: false,
    hasError: false,
    errorMessage: '',
    data: null,

// reducer
function stateReducer(state, action) {
    switch(action.type) {
            // set here 'loading' to true - started request execution
            // return new state
            // set here 'loading' to false - got response
            // set here data that came with action payload
            // return new state
            // set here 'loading' to false - got error response or failed
            // sethere 'errorMessage' that came with action payload 
            // return new state

// you'll have to create 2 new action creators to handle GET_SELECTED_COUNTRY_LOAD // and GET_SELECTED_COUNTRY_FAILED

// now your code should look like this
const getFetchCasesSelectedCountry = (country) => (dispatch) => {
return (
  dispatch({ type: GET_SELECTED_COUNTRY_LOAD });
     .then((result) => {
         // do some stuff with result
              type: GET_SELECTED_COUNTRY_LOADED,
              payload: { /* useful data here */ }
      ).catch(err => {
              type: GET_SELECTED_COUNTRY_FAILED,
              payload: { /* useful error data here */ }

So whenever error happens component that is connected to store will be able to handle it (at least show errorMessage that is can get from the store)

Source: stackoverflow