Why is the second parameter of the Async function in the createAscynThunk() middleware returns an object while a string is expected?
Code from where I dispatch
const handleDateChange = (e) => {
const date = e.target.value;
console.log(date, code); // [date, code]
dispatch(fetchCurrencyByCodeLatestInSpecificDate(date, code));
};
In the code above date and code variables return correctly when I log them to the console.
In my createAsyncThunk middleware
export const fetchCurrencyByCodeLatestInSpecificDate = createAsyncThunk(
FETCH_CURRENCIES_BY_CURRENCY_CODE__IN_SPECIIC_DATE,
async (date, code) => {
console.log(date, code); /* the date ouput result is correct but code returns an object with data =
{extra: undefined, requestId: 'QJrKF6PbWlQQJei9qIpK0', signal: AbortSignal, dispatch: ƒ, getState: ƒ, …}
dispatch: ƒ dispatch()
extra: undefined
fulfillWithValue: ƒ (value, meta)
getState: ƒ i()
rejectWithValue: ƒ (value, meta)
requestId: "QJrKF6PbWlQQJei9qIpK0"
signal: AbortSignal {aborted: false, reason: undefined, onabort: null}
} */
const response = await fetch(`${CURRENCIES_BASE_API_URL}/${date}/currencies/${code}.json`);
const data = await response.json();
return data;
},
);
The return values in the console.
[object][object] describing errors
I tried by exchanging the parameters in the async function and when I did that the date parameter the was returning correctly return the same error.