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

290
Vistas
ReactJS: function post axios error: is not a function

I have a form, and I'm trying to make a post.

In the form when it is submitted I call the saveEntity function:

import { createEntity } from './realmUser-reducer'

export interface IRealmUserUpdateProps extends StateProps, DispatchProps, RouteComponentProps<{ id: string }> { }

export const RealmUserUpdate = (props: IRealmUserUpdateProps) => {
interface LocationState {
    userId: number | string
}
const location = useLocation<LocationState>()

  const saveEntity = (event, errors, values) => {
     if (errors.length === 0) {
       const entity = {
         realm: {id: values.realm},
         user: {userId: location.state}
        }
       props.createEntity(entity)  // this error:  Uncaught (in promise) TypeError: props.createEntity is not a function
    }
   }


return(//.....)


const mapStateToProps = (storeState: IRootState) => (
    {
    });

const mapDispatchToProps = {
    createEntity
}


type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = typeof mapDispatchToProps;

export default connect(mapStateToProps, mapDispatchToProps)(RealmUserUpdate);

in my reducer:

export const createEntity: ICrudPutAction<IRealmUser> = entity => async dispatch => {
    const result = await dispatch({
        type: ACTION_TYPES.CREATE_REALMUSER,
        payload: axios.post(apiUrl, cleanEntity(entity)),
    });
    return result;
};

the model that I created:

export interface IRealmUser {
    id?: string | number | null;
    user?: {
        perCod?: any
    }
    realm?: {
        id?: number | string | null
    }
}

export const defaultValue: Readonly<IRealmUser> = {};

So my problem is that when I'm trying to do the post I receive an error:

the error: Uncaught (in promise) TypeError: props.createEntity is not a function

about the props.createEntity(entity)

EDIT1:

Adding console.log(props)

history: {
    "length": 50,
    "action": "PUSH",
    "location": {
        "pathname": "/realmUser/new",
        "state": 156001,
        "search": "",
        "hash": "",
        "key": "2dwfy5"
    }
}
location:{
    "pathname": "/realmUser/new",
    "state": 156001,
    "search": "",
    "hash": "",
    "key": "2dwfy5"
}
match: {
    "path": "/realmUser/new",
    "url": "/realmUser/new",
    "isExact": true,
    "params": {}
}
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