Помимо этого я неправильно пытался получить данные.
Я пытался получить данные через.
this.props.match.param
Но match не существовало. Не знаю почему но при использовании connect Redux параметры передаются через него.
import * as PropTypes from 'prop-types';
import * as React from 'react';
import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router-dom';
import { Dispatch } from 'redux';
import { IDispatchProps, StudentActions } from '../../actions/studentActions';
import { IAppState } from '../../types';
import { AnswerForm } from './AnswerForm';
interface IStateProps {
serverConnectError: boolean;
serverDataError: boolean;
authState: boolean;
activeTest: number;
testIssuesList: [object];
testState: [object];
id: number;
}
interface IRouterProps {
id: number;
}
type IProps = IStateProps & IRouterProps;
type TProps = IDispatchProps & IStateProps;
class TesterForm extends React.Component<TProps> {
public static contextTypes = {
router: PropTypes.object,
};
constructor(props: any, context: any) {
super(props, context);
}
public componentWillMount() {
alert(this.props.id);
this.props.studentActions.getTestIssues(this.props.activeTest);
}
public render() {
return(
<div className='row'>
<AnswerForm/>
</div>
);
}
}
function mapStateToProps(state: IAppState, ownProps: RouteComponentProps<IRouterProps>): IProps {
return {
serverConnectError: state.commonReducer.serverConnectError,
serverDataError: state.commonReducer.serverDataError,
authState: state.commonReducer.authState,
activeTest: state.studentReducer.activeTest,
testIssuesList: state.studentReducer.testIssuesList,
testState: state.studentReducer.testState,
id: ownProps.match.params.id, // Здесь передаются параметрвы
};
}
function mapDispatchToProps(dispatch: Dispatch<IDispatchProps>): IDispatchProps {
return {
studentActions: new StudentActions(dispatch),
};
}
const connectApp = connect(mapStateToProps, mapDispatchToProps)(TesterForm);
export {connectApp as TesterForm};