Skip to content

Commit 922b1c9

Browse files
committed
Remove the hack thanks to mui#19697
1 parent 3aa1ce7 commit 922b1c9

File tree

4 files changed

+0
-47
lines changed

4 files changed

+0
-47
lines changed

docs/data/data-grid/tree-data/TreeDataSyncRowData.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,6 @@ export default function TreeDataSyncRowData() {
101101
const [rows, setRows] = React.useState(initialRows);
102102
const [loading, setLoading] = React.useState(false);
103103

104-
// WORKAROUND: To persist the expanded parents across re-renders
105-
// Context: https://github.com/mui/mui-x/issues/210#issuecomment-1006411492
106-
const expandedParents = React.useRef(new Set([]));
107-
108-
const isGroupExpandedByDefault = React.useCallback((node) => {
109-
return expandedParents.current.has(node.id);
110-
}, []);
111-
112-
React.useEffect(() => {
113-
return apiRef.current?.subscribeEvent('rowExpansionChange', (node) => {
114-
if (node.childrenExpanded) {
115-
expandedParents.current.add(node.id);
116-
} else {
117-
expandedParents.current.delete(node.id);
118-
}
119-
});
120-
}, [apiRef]);
121-
// WORKAROUND ends here
122-
123104
const handleRowOrderChange = React.useCallback(() => {
124105
setLoading(true);
125106
const updatedOrderedDataRows = gridOrderedDataRowsSelector(apiRef);
@@ -140,7 +121,6 @@ export default function TreeDataSyncRowData() {
140121
treeData
141122
rowReordering
142123
disableRowSelectionOnClick
143-
isGroupExpandedByDefault={isGroupExpandedByDefault}
144124
onRowOrderChange={handleRowOrderChange}
145125
getTreeDataPath={getTreeDataPath}
146126
setTreeDataPath={setTreeDataPath}

docs/data/data-grid/tree-data/TreeDataSyncRowData.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,6 @@ export default function TreeDataSyncRowData() {
105105
const [rows, setRows] = React.useState<GridValidRowModel[]>(initialRows);
106106
const [loading, setLoading] = React.useState(false);
107107

108-
// WORKAROUND: To persist the expanded parents across re-renders
109-
// Context: https://github.com/mui/mui-x/issues/210#issuecomment-1006411492
110-
const expandedParents = React.useRef<Set<GridRowId>>(new Set([]));
111-
112-
const isGroupExpandedByDefault = React.useCallback((node: GridGroupNode) => {
113-
return expandedParents.current.has(node.id);
114-
}, []);
115-
116-
React.useEffect(() => {
117-
return apiRef.current?.subscribeEvent('rowExpansionChange', (node) => {
118-
if (node.childrenExpanded) {
119-
expandedParents.current.add(node.id);
120-
} else {
121-
expandedParents.current.delete(node.id);
122-
}
123-
});
124-
}, [apiRef]);
125-
// WORKAROUND ends here
126-
127108
const handleRowOrderChange: DataGridProProps['onRowOrderChange'] =
128109
React.useCallback(() => {
129110
setLoading(true);
@@ -145,7 +126,6 @@ export default function TreeDataSyncRowData() {
145126
treeData
146127
rowReordering
147128
disableRowSelectionOnClick
148-
isGroupExpandedByDefault={isGroupExpandedByDefault}
149129
onRowOrderChange={handleRowOrderChange}
150130
getTreeDataPath={getTreeDataPath}
151131
setTreeDataPath={setTreeDataPath}

docs/data/data-grid/tree-data/TreeDataSyncRowData.tsx.preview

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
treeData
77
rowReordering
88
disableRowSelectionOnClick
9-
isGroupExpandedByDefault={isGroupExpandedByDefault}
109
onRowOrderChange={handleRowOrderChange}
1110
getTreeDataPath={getTreeDataPath}
1211
setTreeDataPath={setTreeDataPath}

docs/data/data-grid/tree-data/tree-data.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ If you want to update the external row data, for example to persist it in the lo
197197

198198
{{"demo": "TreeDataSyncRowData.js", "bg": "inline", "defaultCodeOpen": false}}
199199

200-
:::warning
201-
Syncing the external rows and providing a fresh [rows prop](/x/react-data-grid/row-updates/#the-rows-prop) reference causes a full tree regeneration, whose one side effect is that the expanded rows state will be lost.
202-
203-
To persist the expanded rows state, you can use the `isGroupExpandedByDefault()` callback with a dictionary, as done in the above demo.
204-
:::
205-
206200
## Lazy-loading tree data children
207201

208202
See [Server-side data—Tree data](/x/react-data-grid/server-side-data/tree-data/) for details on lazy-loading tree data children.

0 commit comments

Comments
 (0)