Define a presentational component vs a container component
Define combine reducers
Define action creators
Describe a folder structure for redux
import {combineReducers} from 'redux';
import currentUser from './currentUser';
import messages from './messages';
const rootReducer = combineReducers({
currentUser,
messages,
});
export default rootReducer;
combineReducers
const messages = (state=[], action) => {
switch(action.type) {
case "LOAD_MESSAGES":
return [...action.messages];
case "ADD_MESSAGE":
return [action.message, ...state];
default:
return state;
}
};
export default messages;
Messages Reducer
Action Creators
const mapDispatchToProps = dispatch => ({
onLogout() {
dispatch({
type: "USER_LOGOUT"
})
},
});
const mapDispatchToProps = dispatch => ({
onLogout() {
dispatch(actions.userLogout())
},
});