import { useMemo } from 'react'
import type { LayerType } from '../types'

export function useInstantiatedLayers(layers: LayerType[]) {
  return useMemo(
    () =>
      layers
        .filter((l) => !!l?.type && !!l?.props?.data)
        .map(({ type: Layer, props }) => new Layer!(props)),
    [layers],
  )
}
