const getTree = React.useCallback((map: Map<any, any>, parent_id?: any, data?: any[]) => { if (!data) return []; return data.filter(e => e.parent_id === parent_id).map(e => { const item = { title: e.name, key: e.id, children: getTree(map, e.id, data) } map.set(item.key, item); return item; }) }, []);