i'm working on my react blog project and i'm making a get request using an api using (redux-react) but my problem is that the function is been called continuously, instead it been called once
below is my code and image showing the continuous api call
pls can anyone help out
action file where i'm making d api call
export function fetchArticles(){
return function(dispatch){
const url = `${baseUrl}/articles/list`
return axios.get(url).then(res =>{
console.log(res.data)
dispatch( {type:articles.DISPLAY_ARTICLE, payload:res.data.data})
})
}
}
reducer file
function displayArticles (state=initialState, action){
if(action.type===DISPLAY_ARTICLE){
console.log(state)
return Object.assign({}, state,{
articles: state.articles.concat(action.payload)
})
}
console.log(state)
return state
}
function rootReducer(state=initialState, action){
switch(action.type){
case DISPLAY_ARTICLE:
return displayArticles(state, action)
break;
component file
function mapStateToProp (state){
return {articles: state.articles}
}
const Index = (props)=>{
useEffect(()=>{
props.fetchArticles()
}
)
export default connect(
(mapStateToProp),
{fetchArticles}
)(Index)