While dispatching the event I am facing the issue "Argument of type '(dispatch: any) => Promise' is not assignable to parameter of type 'AnyAction'." I am new to React 18 and redux toolkit. Using Redux-thunk, everything seems fine, but dispatching the event gives an error: The error is shown in the Action file while dispatching . Seems the issue is with return type. Not able to find a solution for it.
import { Provider } from 'react-redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { legacy_createStore as createStore , applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
const store = createStore(rootReducer,composeWithDevTools(applyMiddleware(thunk)));
ReactDOM.render(<Provider store={store}>
<App/>
</Provider>,document.getElementById('root'));
PlayerDetails.Action.tsx
import * as ACTION_TYPES from './action-types';
import * as CONSTANTS from '../utils/Constants'
const axios = require('axios');
const rax = require('retry-axios');
export const playerDetails_request = (data: any)=>{
return {
type: ACTION_TYPES.GET_PLAYER_DETAILS_REQUEST,
payload : data
}
}
export const playerDetails_success = (obj: any)=>{
return {
type: ACTION_TYPES.GET_PLAYER_DETAILS_SUCCESS,
payload : obj
}
}
export const playerDetails_failure = (err: any)=>{
return {
type: ACTION_TYPES.GET_PLAYER_DETAILS_FAILURE,
payload : err
}
}
export default function getPlayersDetails(data:any){
return async function (dispatch:any) {
dispatch(playerDetails_request(data));
try{
axios.defaults.withCredentials = true;
const interceptorId = rax.attach();
const response = await axios ({
url:CONSTANTS.PLAYER_DETAILS,
method:'GET',
params: {page: '0', per_page: '25'},
headers: CONSTANTS.header,
//data:()
});
if(response !==null && response.status === 200){
dispatch(playerDetails_success(response));
}else{
dispatch(playerDetails_failure(response));
}
}catch(error){
console.log("ERROR");
dispatch(playerDetails_failure("ERROR"))
}
}
}
action-types.tsx
export const GET_PLAYER_DETAILS_REQUEST = "GET_PLAYER_DETAILS_REQUEST"
export const GET_PLAYER_DETAILS_SUCCESS = "GET_PLAYER_DETAILS_SUCCESS"
export const GET_PLAYER_DETAILS_FAILURE = "GET_PLAYER_DETAILS_FAILURE"