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": {}
}