import { NewsReducerAction , NewsReducerActionTypes , NewsReducerState , } from '../../types/redux/news-reducer-types' ; const initialNewsState = { areNewsLoading : false , newsArticles : [ ] , error : null , } ; function param { initialNewsState } state param { object } action returns { object } export const newsReducer = ( state = initialNewsState , action ) : NewsReducerState => { switch ( action . type ) { case NewsReducerActionTypes . LOAD_NEWS_ARTICLES : return { ... state , areNewsLoading : true } ; case NewsReducerActionTypes . NEWS_ARTICLES_DID_LOAD : return { ... state , areNewsLoading : false , newsArticles : action . payload } ; case NewsReducerActionTypes . NEWS_ARTICLES_LOAD_ERROR : return { ... state , areNewsLoading : false , error : action . payload } ; case NewsReducerActionTypes . CLEAR_NEWS_STATE : return initialNewsState ; default : return state ; } } ;