Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda