import React, { useLayoutEffect } from 'react' import type { PropsWithChildren } from 'react' import type { UnistylesThemes } from '../global' import { UnistylesShadowRegistry } from '../specs' import { ApplyScopedTheme } from './ApplyScopedTheme' interface NamedThemeProps extends PropsWithChildren { name: keyof UnistylesThemes | undefined, previousScopedTheme?: string } export const NamedTheme: React.FunctionComponent = ({ name, children, previousScopedTheme }) => { const mappedChildren = [ , children, ] useLayoutEffect(() => { // this will affect only scoped styles as other styles are not yet mounted UnistylesShadowRegistry.flush() }) return ( {mappedChildren} ) }