Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
I have some issue with redux thunk, i am unable to use getState() in my actions file

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


The error i am getting is:

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda