import React, { memo } from 'react' import { FC, ComponentType as CT } from 'react' import { doczState, Database, ThemeConfig, TransformFn, Entry } from './state' export interface ThemeProps { db: Database currentEntry: Entry children(WrappedComponent: CT): JSX.Element } export function theme( themeConfig: ThemeConfig, transform: TransformFn = c => c ): (WrappedComponent: CT) => CT { return WrappedComponent => { const Theme: FC = memo(props => { const { db, currentEntry, children } = props const initial: any = { ...db, currentEntry, themeConfig, transform } return ( {children} ) }) Theme.displayName = WrappedComponent.displayName || 'DoczTheme' return Theme } }