Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import {
  2. GET_POSTS,
  3. GET_POSTS_SUCCESS,
  4. GET_POSTS_FAILURE
  5. } from "./../actions/actions";
  6.  
  7. const INITIAL_STATE = { posts: [], error: null, loading: false, totalpages: 0 };
  8.  
  9. const Posts = (state = INITIAL_STATE, action) => {
  10. let error;
  11. switch (action.type) {
  12. case GET_POSTS:
  13. return { posts: [], error: null, loading: true, totalpages: 0 };
  14.  
  15. case GET_POSTS_SUCCESS:
  16. return {
  17. posts: action.payload,
  18. error: null,
  19. loading: false,
  20. totalpages: action.totalpages
  21. };
  22.  
  23. case GET_POSTS_FAILURE:
  24. error = action.payload || { message: action.payload.message };
  25. return { posts: [], error: error, loading: false, totalpages: 0 };
  26.  
  27. default:
  28. return state;
  29. }
  30. };
  31.  
  32. export default Posts;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement