@@ -2,7 +2,7 @@ import { ListItemIcon, ListItemText } from '@material-ui/core'
22import TreeItem from '@material-ui/lab/TreeItem'
33import { GenericContent } from '@sensenet/default-content-types'
44import { useRepository } from '@sensenet/hooks-react'
5- import React , { MouseEventHandler , useCallback , useContext , useEffect , useState } from 'react'
5+ import React , { MouseEventHandler , useCallback , useContext , useEffect , useRef , useState } from 'react'
66import { useHistory } from 'react-router'
77import { ResponsivePersonalSettings } from '../../context'
88import { useQuery , useSnRoute } from '../../hooks'
@@ -37,11 +37,22 @@ export const StyledTreeItem = (props: StyledTreeItemProps) => {
3737 const snRoute = useSnRoute ( )
3838 const uiSettings = useContext ( ResponsivePersonalSettings )
3939 const { navigate, editMode, ...restProps } = props
40+ const mountedRef = useRef ( true )
41+
42+ useEffect ( ( ) => {
43+ mountedRef . current = true
44+ return ( ) => {
45+ mountedRef . current = false
46+ }
47+ } , [ ] )
4048
4149 const loadCollectionCB = useCallback (
4250 async ( contentPath : string ) : Promise < void > => {
4351 try {
4452 const children = await loadChildren ( contentPath )
53+ if ( ! mountedRef . current ) {
54+ return
55+ }
4556 children ?. sort ( ( a , b ) => {
4657 const isAFolder = a . Type . toLowerCase ( ) . includes ( 'folder' ) ? 0 : 1
4758 const isBFolder = b . Type . toLowerCase ( ) . includes ( 'folder' ) ? 0 : 1
0 commit comments