1- import type { HTMLAttributes , ReactNode } from 'react' ;
2- import { createElement , forwardRef , useEffect , useMemo } from 'react' ;
1+ import type { HTMLAttributes , ReactNode , ElementType } from 'react' ;
2+ import { forwardRef , useEffect , useMemo } from 'react' ;
33
44import { createStyleObject } from '@/lib/utils' ;
55import type { DataAttributes , LibraryProps } from '@/lib/NativeProps' ;
@@ -12,26 +12,36 @@ export type LocalRootProps = DataAttributes &
1212 LibraryProps &
1313 HTMLAttributes < HTMLElement > & {
1414 children ?: ReactNode ;
15- /** Choose which HTMLElement to render as a root. div is default. */
16- as ?: string ;
17- /** Apply initial theme. */
15+ /** Choose which HTMLElement to render as a root. ` div` is the default value . */
16+ as ?: ElementType ;
17+ /** Apply the initial theme. */
1818 theme ?: Theme ;
19- /** Provide theme setter function. */
19+ /** Provide a theme setter function. */
2020 setTheme ?: ( arg0 : Theme ) => void ;
2121 } ;
2222
2323export const LocalRoot = forwardRef < HTMLElement , LocalRootProps > ( ( props , ref ) => {
2424 // This is needed to fix an error introduced in version 0.6.14.
2525 // Props were not transported to returned HTMLElement.
26- const { children, as = 'div' , theme = { } , setTheme = ( ) => { } , ...restProps } = props ;
26+ const {
27+ children,
28+ as : Component = 'div' ,
29+ theme = { } ,
30+ setTheme = ( ) => { } ,
31+ ...restProps
32+ } = props ;
2733
2834 const initialStyle = useMemo ( ( ) => createStyleObject ( theme ) , [ theme ] ) ;
2935
3036 useEffect ( ( ) => {
3137 setTheme ( theme ) ;
3238 } , [ theme , setTheme ] ) ;
3339
34- return createElement ( as , { ...restProps , style : initialStyle , ref} , children ) ;
40+ return (
41+ < Component ref = { ref } style = { initialStyle } { ...restProps } >
42+ { children }
43+ </ Component >
44+ ) ;
3545} ) ;
3646
3747LocalRoot . displayName = 'LocalRoot' ;
0 commit comments