【发布时间】:2021-04-18 11:24:47
【问题描述】:
我正在使用AgGridReact 构建一个反应功能组件:
const DataGrid = (props) =>
{
const [gridRowData, setGridRowData] = useState([]);
const [columnDefinition, setColumnDefinition] = useState([]);
useEffect(async () =>
{
if(props.name && props.name !== "")
{
... get grid row data and column definition here according to props.name - working fine
}
},[props.name]);
let frameworkComponents = {
customLoadingOverlay: LoadingOverlayTemplate,
customNoRowsOverlay: UxDataGridCustomNoRows,
editButton: params => <ViewAndDeleteSetting {...params}
openAddConfigurationsWindow={openAddConfigurationsWindow}
onDeleteSetting={onDeleteSetting} />
};
.
.
.
const onDeleteSetting = async () =>
{
console.log("ON DELETE AND NAME IS: " + props.name ); //PRINTS AN EMPTY STRING
...
}
return (
<AgGridReact
columnDefs={columnDefinition}
rowData={gridRowData}
frameworkComponents={frameworkComponents}/>
);
正如您在onDeleteSetting 的评论中看到的,调用此回调时名称为空。单元格本身的渲染很好,ViewAndDeleteSetting 确实被渲染了,只是它似乎只被渲染一次,而不是每次名称更改时。如何使用最新的frameworkComponents 重新呈现内部ViewAndDeleteSetting 组件?
【问题讨论】:
-
你的
onDeleteSetting函数读取了 agGrid 组件的 props,所以如果你不使用新的 props 刷新整个组件,名称打印将是相同的。我不明白为什么您认为名称会更改,但也许可以尝试从ViewAndDeleteSetting组件向onDeleteSetting方法添加参数。
标签: reactjs ag-grid ag-grid-react