I have a dispatch function:
const dispatch = useAppDispatch()
const handleFetch = (e: React.MouseEvent<HTMLAnchorElement>) => {
const target = e.target as Element
dispatch(fetchCity(parseInt(target.id)))
localStorage.setItem('location', target.id)
}
The async thunk function looks like this:
export const fetchCity = createAsyncThunk('city/fetchCity', async (id: number) => {
const res = await fetch(`${apiUrl}/${id}`)
.then(res => res.json())
return res
})
My useAppDispatch hook looks like this, It's same as the one in redux typescript docs:
import type { AppDispatch } from "./redux/store";
export const useAppDispatch: () => AppDispatch = useDispatch
The AppDispatch type looks like this, It's, again, from redux typescript docs:
export type AppDispatch = typeof store.dispatch
The problem is in the
dispatch(fetchCity(parseInt(target.id)))
The error says this: Argument of type 'AsyncThunkAction<any, number, {}>' is not assignable to parameter of type 'AnyAction'.
I even tried just doing:
dispatch(fetchCity(1))
And I got the same error.
What do I do, I'm confused because I did all of this the same as it was in the redux docs?