我正在尝试在 React-table 中的 onclick 函数内进行重定向。当您查看 onRowClick 时,它会记录完美运行的标题名称。但是当我在点击后尝试使用重定向时,什么也没有发生。该代码在我在不同的组件中尝试后有效。我想知道这是否是 react-table 的问题,是否还有其他方法可以做到这一点?
我想要做的是 onclick 重定向到附加有 Patientinfo 组件的路由。
import React, { Component } from 'react';
import { highRiskPatientData } from '.././dummydata/HighRiskPatientComp';
import '.././styles/HighRiskPatientComp.css';
import ReactTable from 'react-table/lib';
import "react-table/react-table.css";
import "babel-polyfill";
import PatientInfo from './PatientInfo';
import { Redirect } from 'react-router-dom';
class HighRiskPatientComponent extends Component {
// constructor() {
// super();
// }
render() {
const onRowClick = (state, rowInfo, column, instance) => {
return {
onClick: e => {
console.log('It was in this column:', column.Header);
<Redirect to="/patientinfo"/>
}
}
}
return (
<div className="container-fluid">
<div className="row">
<div className="col-md-6 HighRiskHeaderDiv">
<h5 className="HighRiskHeader">High Risk Patients</h5>
</div>
<div className="col-md-6 btnSettingsDiv">
<button type="button" className="btn btnSettings"
value="Submit">Settings</button>
</div>
</div>
<ReactTable
data={highRiskPatientData.data}
columns={[
{
columns: [
{
Header: "Name",
accessor: "name"
},
{
Header: "Current PRF Status",
accessor: "currentPRFStatus"
},
{
Header: "Review On",
accessor: "reviewOn"
},
{
Header: "Due/Overdue",
accessor: "DueOverdue"
},
{
Header: "Facility",
accessor: "Facility"
},
{
Header: "Last Discharge",
accessor: "lastDischarge"
},
{
Header: "Last MHA Appt",
accessor: "lastMHAppt"
},
{
Header: "Next MHA Appt",
accessor: "nextMHAppt"
},
{
Header: "On Track",
accessor: "onTrack"
},
{
Header: "Last Safety Plan",
accessor: "lastSafetyPlan"
},
{
Header: "Done in 7 Days",
accessor: "doneIn7Days"
},
{
Header: "Last Compreh. Risk Assess",
accessor: "lastCompRiskAssess"
},
{
Header: "PHQ-9 Score",
accessor: "phqDash9Score"
},
{
Header: "PHQ-9 date",
accessor: "phqDash9Score"
},
{
Header: "Trend",
accessor: "trend"
}
]
}
]}
defaultPageSize={8}
className="-highlight"
getTdProps={onRowClick}
/>
</div>
);
}
}
export default HighRiskPatientComponent;