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

195
Vistas
dispatch is not a function TypeError

I'm new to react-redux and I'm using the react-thunk middleware. I'm getting the error "Uncaught TypeError: dispatch is not a function" whenever I try to run my action creator (by pressing my button). Anyone know what's going on?

src/actions/index.js

function editUserName (newUserName) {
    return {
        type: 'CHANGE_USER_NAME',
        newUserName: newUserName
    }
}

export function editUserNameDelegate () {
    return function (dispatch, getState) {
        return dispatch(editUserName("thunkUser"))
    }
}

src/containers/admin.js

import { editUserNameDelegate } from '../actions/index'
...
<input type="button" onClick={ editUserNameDelegate() } value="edit UserName" />
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You're executing the editUserNameDelegate function inside of render, instead of passing it as the onClick handler. You want onClick={editUserNameDelegate} instead.

Also, if you're writing it that way, you need to make sure that the function is bound up to dispatch when you call it. You can do that like:

export default connect(null, {editUserNameDelegate})(MyComponent)

And then pass onClick={this.props.editUserNameDelegate} in your render function.

over 4 years ago · Santiago Trujillo Denunciar

0

The store is what provides the dispatch function. So you either need to connect your component to the store using something like connect from react-redux (https://github.com/reactjs/react-redux), or you need to call store.dispatch(editUserNameDelegate()).

You also need to make sure you have added redux-thunk as middleware in your store. See more about redux-thunk here: https://github.com/gaearon/redux-thunk

over 4 years ago · Santiago Trujillo Denunciar

0

You should provide what is src/containers/admin.js function or class?

If it is function component you should use onClick={() => editUserNameDelegate()}

over 4 years ago · Santiago Trujillo Denunciar
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