I am trying to figure out how to pass down props into components when using typescript.
The error I receive if I try to pass down any prop anywhere, whether it be local state or anything but {...this.props}. But if I pass down this.props, I don't get anything that I want on the other end. Instead I get history, location, match with their applicable defaults and staticContext: undefined. If I try to pass down actions, as in my example below, then it will be undefined.
The error I get as a result is
client:157 [at-loader] ./src/containers/App/index.tsx:25:31
TS2339: Property 'actions' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Home> & Readonly<{ children?: ReactNode; }> & Read...'.
My App.tsx is below:
import * as React from 'react';
import * as HomeActions from '../../actions/home';
import * as style from './style.css';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router';
import { RootState } from '../../reducers';
import Home from '../../components/Home';
export namespace App {
export interface Props extends RouteComponentProps<void> {
actions: typeof HomeActions
}
export interface State {
/* empty */
}
}
export class App extends React.Component<App.Props, App.State> {
render() {
return (
<div>
<Home {...this.props} actions={this.props.actions}/>
{this.props.children}
</div>
);
}
}
function mapStateToProps(state: RootState) {
return {
home: state.home
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(HomeActions as any, dispatch)
};
}
connect(mapStateToProps, mapDispatchToProps);
In the home component, when I log this.props.actions in onComponentDidMount(){} then I get undefined.