繁体   English   中英

我们可以使用功能组件并与 ag-grid 表反应挂钩吗?

[英]Can we use functional component and react hook with ag-grid table?

当我使用 ag-grid 并一次性反应钩子时出现错误。 我能解决这个问题吗? 我有“gridApi.paginationGoToNextPage 不是函数”之类的问题。

  const onBtNext = () => {
    setTestVar(5);//this is var that defined via react hook, if I not delete this, I will have error
    gridApi.paginationGoToNextPage()
    console.log(gridApi.paginationGetTotalPages())
  }

如果我不使用反应钩子,这段代码可以完美运行,但我需要它

尝试在功能组件中使用 Ref 存储 gridApi,如下所示:

    const gridApi = useRef(null);

    const onGridReady = params => {
         gridApi.current = params.api;
    };

    const onBtNext = () => {
        setTestVar(5);
        gridApi.current.paginationGoToNext();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM