Skip to content
On this page

generateTree

Compose tree.

Usage

ts
import { generateTree } from '@use-kit/functions'

const list = [
  { id: 'nogi', },
  { id: 'asuka', parent: 'nogi' },
  { id: 'shiori', parent: 'nogi' }
]
const ret = generateTree(list)

// expect:
// [
//   {
//     id: 'nogi',
//     children: [
//       { id: 'asuka', parent: 'nogi' },
//       { id: 'shiori', parent: 'nogi' }
//     ]
//   }
// ]
import { generateTree } from '@use-kit/functions'

const list = [
  { id: 'nogi', },
  { id: 'asuka', parent: 'nogi' },
  { id: 'shiori', parent: 'nogi' }
]
const ret = generateTree(list)

// expect:
// [
//   {
//     id: 'nogi',
//     children: [
//       { id: 'asuka', parent: 'nogi' },
//       { id: 'shiori', parent: 'nogi' }
//     ]
//   }
// ]

Released under the MIT License.