it shows me error every time whenever i call my action from my component. I'm using typescript with react redux.
Error : Property 'getItem' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.
MY Action
import * as actionTypes from "../types";
import { getItems } from "../api/allApi";
export const getItem = () => {
const payload = getItems();
return {
type: actionTypes.GET_ITEM,
payload
};
};
My Component
import React from "react";
import "../styles/settings.scss";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { getItem } from "../Actions/action";
class Settings extends React.Component {
componentDidMount() {
this.props.getItem(); // error here: Property 'getItem' does not exist on //type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.ts(2339)
}
render() {
return (
<div>
{console.log(this.props.items)} // Error here: Property 'items' //does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'
{/* {console.log("asda", this.props.items)} */}
</div>
);
}
}
const mapStateToProps = (state: any) => {
return {
items: state.getItemsReducer
};
};
const mapDispatchToProps = (dispatch: any) => {
return bindActionCreators({ getItem }, dispatch);
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(Settings);
any's. For example the return type ofmapStateToPropsisIPropsorPartial<IProps>, if you decide to populate with more props. Also, it's state should bestate:{ getItemsReducer: soneType[]}. Not sure about the actual output but you can figure it out...