import { Dispatch } from 'redux' ; import { NewsReducerAction , NewsReducerActionTypes , } from '../../types/redux/news-reducer-types' ; import { getLatestNews } from '../../frontend-rest-client/rest/news' ; import { getErrorMessage } from '../../utils/getErrorMessage' ; Action function returns { function } export const loadLatestNews = ( ) => { return async ( dispatch ) : Promise < void > => { dispatch ( { type : NewsReducerActionTypes . LOAD_NEWS_ARTICLES } ) ; try { const { data } = await getLatestNews ( ) ; dispatch ( { type : NewsReducerActionTypes . NEWS_ARTICLES_DID_LOAD , payload : data . articles , } ) ; } catch ( error ) { dispatch ( { type : NewsReducerActionTypes . NEWS_ARTICLES_LOAD_ERROR , payload : getErrorMessage ( error ) , } ) ; } } ; } ;