Store.js (in Main Src Folder)
Actions (Src/Actions/...)
Reducers (Src/Reducers/...)
Store.js (in Main Src Folder)
Actions (Src/Actions/...)
Reducers (Src/Reducers/...)
// actions | |
import axios from 'axios'; | |
import { setAlert } from './alert'; | |
import { GET_POSTS, POST_ERROR } from './types'; | |
// Get Posts | |
export const getPosts = () => async dispatch => { | |
try { | |
// Write your stuff here | |
} catch (err) { | |
// Handle errors | |
} | |
} |
import { combineReducers } from 'redux'; | |
import alert from './alert'; | |
import auth from './auth'; | |
import profile from './profile'; | |
import post from './post'; | |
export default combineReducers({ | |
alert, | |
auth, | |
profile, | |
post | |
}); |
// In Reducers | |
import { GET_POSTS, POST_ERROR } from '../actions/types'; | |
const initialState = { | |
posts: [], | |
post: null, | |
loading: true, | |
error: {} | |
}; | |
export default function(state = initialState, actions) { | |
const { type, payload } = actions; | |
switch (type) { | |
case GET_POSTS: | |
return { | |
...state, | |
posts: payload, | |
loading: false | |
}; | |
case POST_ERROR: | |
return { | |
...state, | |
error: payload, | |
loading: false | |
}; | |
default: | |
return state; | |
} | |
} |
export const SET_ALERT = 'SET_ALERT'; | |
export const REMOVE_ALERT = 'REMOVE_ALERT'; | |
export const REGISTER_SUCCESS = 'REGISTER_SUCCESS'; | |
export const REGISTER_FAIL = 'REGISTER_FAIL'; | |
export const USER_LOADED = 'USER_LOADED'; | |
export const AUTH_ERROR = 'AUTH_ERROR'; | |
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; | |
export const LOGIN_FAIL = 'LOGIN_FAIL'; | |
export const LOGOUT = 'LOGOUT'; | |
export const CLEAR_PROFILE = 'CLEAR_PROFILE'; | |
export const GET_PROFILE = 'GET_PROFILE'; | |
export const GET_PROFILES = 'GET_PROFILES'; | |
export const PROFILE_ERROR = 'PROFILE_ERROR'; | |
export const UPDATE_PROFILE = 'UPDATE_PROFILE'; | |
export const ACCOUNT_DELETED = 'ACCOUNT_DELETED'; | |
export const GET_REPOS = 'GET_REPOS'; | |
export const GET_POST = 'GET_POST'; | |
export const POST_ERROR = 'POST_ERROR'; |