Chunk out the different routers and clean up feature logic

This commit is contained in:
DaneEveritt 2022-06-12 11:56:00 -04:00
parent 04e97cc67e
commit 7197d28815
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 54 additions and 32 deletions

View file

@ -0,0 +1,19 @@
import React, { useMemo } from 'react';
import features from './index';
import { getObjectKeys } from '@/helpers';
type ListItems = [ string, React.ComponentType ][];
export default ({ enabled }: { enabled: string[] }) => {
const mapped: ListItems = useMemo(() => {
return getObjectKeys(features)
.filter(key => enabled.map((v) => v.toLowerCase()).includes(key.toLowerCase()))
.reduce((arr, key) => [ ...arr, [ key, features[key] ] ], [] as ListItems);
}, [ enabled ]);
return (
<React.Suspense fallback={null}>
{mapped.map(([ key, Component ]) => <Component key={key}/>)}
</React.Suspense>
);
};