I am using function component in react with typescript. Here is what my component looks like
const Table = (props: TableProps) => {
const [gridApi, setGridApi] = React.useState(() => {})
const gridOptions = {
rowData: rowData,
columnDefs: columnDef,
pagination: true,
}
const onGridReady = (params) => {
setGridApi(params.api);
}
return (
<div className="ag-theme-alpine" >
<AgGridReact gridOptions={gridOptions} onGridReady={onGridReady}/>
</div>
);
};
I need to get the gridApi so I can use it in a handler for another component to do quick filtering.
Looking at the docs HERE, the recommended way is to grab the gridApi and store it in a state. Considering that I am using function component here is what I did
const [gridApi, setGridApi] = React.useState(() => {})
When I do this in the handler:
const handleTableFilter = (filterText: string) => {
gridApi.setQuickFilter(filterText) // error here - Property 'setQuickFilter' does not exist on type '() => void'.
}
Typescript complains that Property 'setQuickFilter' does not exist on type '() => void'.
I also tried the pattern recommended for Javascript HERE but I could not quite figure that out too.
I would appreciate some help on how to store the gridApi in my use case (Typescript, React using Function components - react hooks). If possible, I would prefer a solution where I will not have to store a function in useState. If not, I a fine with any solution.