【发布时间】:2019-09-15 17:37:33
【问题描述】:
我正在尝试使用 React Table、react-csv 包和 TypeScript 来实现下载功能。
我正在尝试使用createRef() 为表格组件创建和使用引用,但是它引发了以下异常
“'RefObject' 类型上不存在属性 'getResolvedState'”错误。
我的代码如下:
import {CSVLink} from "react-csv";
import * as React from 'react';
import ReactTable from 'react-table';
export default class Download extends React.Component<{},{}> {
private reactTable: React.RefObject<HTMLInputElement>;
constructor(props:any){
super(props);
this.state={} // some state object with data for table
this.download = this.download.bind(this);
this.reactTable = React.createRef();
}
download(event: any)
{
const records =this.reactTable.getResolvedState().sortedData; //ERROR saying getResolved state does not exist
//Download logic
}
render()
{
return(
<React.Fragment>
<button onClick={this.download}>Download</button>
<ReactTable
data={data} //data object
columns={columns} //column config object
ref={this.reactTable}
/>
</React.Fragment>
}
}
Any help would be appreciated
【问题讨论】:
标签: reactjs typescript ref react-table