composeTree
Compose tree.
TIP
It compose tree for one root node, recommended to use generateTree to supported multiple root nodes.
Usage
ts
import { composeTree } from '@use-kit/functions'
const list = [
{ id: 'nogi', },
{ id: 'asuka', parent: 'nogi' },
{ id: 'shiori', parent: 'nogi' }
]
const ret = composeTree(list)
// expect:
// [
// {
// id: 'nogi',
// children: [
// { id: 'asuka', parent: 'nogi' }, { id: 'shiori', parent: 'nogi' }
// ]
// }
// ]import { composeTree } from '@use-kit/functions'
const list = [
{ id: 'nogi', },
{ id: 'asuka', parent: 'nogi' },
{ id: 'shiori', parent: 'nogi' }
]
const ret = composeTree(list)
// expect:
// [
// {
// id: 'nogi',
// children: [
// { id: 'asuka', parent: 'nogi' }, { id: 'shiori', parent: 'nogi' }
// ]
// }
// ]