Action:
export const fetchNewsSuccess = (article) => ({
type: NewsActionTypes.FETCH_NEWS_SUCCESS,
payload: article,
});
export const fetchNewsBeginAsync = () => {
return (dispatch) => {
const collectionRef = fireStore.collection('news');
dispatch(fetchNewsBegin());
collectionRef
.get()
.then((snapshot) => {
dispatch(fetchNewsSuccess(snapshot));
})
.catch((error) => dispatch(fetchNewsFailure(error.message)));
};
};
Reducer
const newsReducer = (state = INITIAL_STATE, action) => {
switch (action.payload) {
case NewsActionTypes.FETCH_NEWS_BEGIN:
return {
...state,
isFetching: true,
};
case NewsActionTypes.FETCH_NEWS_SUCCESS:
return {
...state,
isFetching: false,
news: action.payload,
};
}
}
I'm trying to get article data from firebase database, fetching data in action (with redux-thunk) fetchNewsBeginAsync then my action has payload but state not updating can anyone help me pls
snapshot
and see what you are getting from firebase – Yousaf