2022-06-12 15:56:00 +00:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import features from './index';
|
2022-06-26 18:34:09 +00:00
|
|
|
import { getObjectKeys } from '@/lib/objects';
|
2022-06-12 15:56:00 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
type ListItems = [string, React.ComponentType][];
|
2022-06-12 15:56:00 +00:00
|
|
|
|
|
|
|
export default ({ enabled }: { enabled: string[] }) => {
|
|
|
|
const mapped: ListItems = useMemo(() => {
|
|
|
|
return getObjectKeys(features)
|
2022-06-26 19:13:52 +00:00
|
|
|
.filter((key) => enabled.map((v) => v.toLowerCase()).includes(key.toLowerCase()))
|
|
|
|
.reduce((arr, key) => [...arr, [key, features[key]]], [] as ListItems);
|
|
|
|
}, [enabled]);
|
2022-06-12 15:56:00 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Suspense fallback={null}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{mapped.map(([key, Component]) => (
|
|
|
|
<Component key={key} />
|
|
|
|
))}
|
2022-06-12 15:56:00 +00:00
|
|
|
</React.Suspense>
|
|
|
|
);
|
|
|
|
};
|