i have copied my related code down below. please see if you can help me. i am creating a chat application with MERN stack and socket.io .Also i want to know is there any way we can store the chat messages in database. i am thinking it will be too much load on the db server as i have to make a post request everytime a user sends a message.Thank you for your help in advance. This is store.js file
enter coimport { applyMiddleware, createStore, compose } from 'redux'
import rootReducer from './reducers'
import thunk from 'redux-thunk'
const initialState = {};
const composeEnhancers =
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
}) : compose;
const enhancer = composeEnhancers(
applyMiddleware(thunk),
);
const store = createStore(rootReducer,initialState, enhancer);
export default store;
chatActions.js
export const sendMsg=(msg)=> (getState,dispatch)=>{
const socket = getState().chat.socket
socket.emit('message',msg)
.then(dispatch({
type:'SAVE_MSG',
payload:msg
}))
}
chatReducer.js
const initialState= {
msgList:[],
socket:{},
msgAreaChat:[]
}
const chatReducer = (state=initialState,action)=>{
switch(action.type){
case 'SAVE_MSG':
return{
...state,
msgList:[...state.msgList,action.payload]
}
case 'GET_SOCKET':
return{
...state,
socket:action.payload
}
default:
return{
...state
}
}
}
export default chatReducer