在OnGridReady AgGridReact中运行Redux Hook

时间:2020-07-09 09:16:40

标签: redux react-hooks ag-grid ag-grid-react

我正在尝试使用AgGridReact中的数据源功能来检索无限滚动中的数据。

但是我的数据是通过redux钩子检索的,我无法调用我的函数,因为它总是返回错误

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

我将AgGrid放在a内并与容器连接。

...
const onGridReady = (params) => {
        params.api.sizeColumnsToFit();
            this.gridApi = params.columnApi;

            const datasource = {
                getRows: (params) => {
                    var rowsThisPage = functionFetcher();  // This is the function
                    params.successCallback(rowsThisPage, -1);
                }
            }
            params.api.setDatasource(datasource);
    }

    return (
        <div className="ag-theme-balham" style={styleGrid}>
            <AgGridReact
                gridOptions={gridOptions}
                onGridReady={onGridReady}>
            </AgGridReact>
        </div>
    );

0 个答案:

没有答案