Before connecting Redux to our application, let's set up Redux for our whatsappClone app:
- First of all, let's create an addMessage action and put it inside the app/actions.js file:
export const actionTypes = {
ADD_MESSAGE: 'ADD_MESSAGE'
}
export function addMessage(message){
return {
type: actionTypes.ADD_MESSAGE,
payload: {
message,
incoming: false
}
}
}
- Next, let's create a reducers folder and add the messagesReducer.js and index.js files. Inside index.js, we will simply import and export messagesReducer; however, in a real-world app, it will usually export the combineReducers function result:
import { combineReducers } from 'redux';
import messages from './messagesReducer'
export default messages;
- Our messagesReducer.js will be as follows:
import { actionTypes } from...