File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,11 @@ import React, {
99 useState ,
1010} from 'react'
1111
12- type Theme = Record < string , string | number | boolean >
13-
1412/**
1513 * Creates `React.Context` for a theme, exposes its `Provider` as well as some
1614 * utility functions and hooks for getting and setting the theme.
1715 */
18- export default class ThemeContext < T extends Theme > {
16+ export default class ThemeContext < T extends object > {
1917 private Context : React . Context < [ T , Dispatch < SetStateAction < T > > ] >
2018
2119 /**
@@ -66,13 +64,15 @@ export default class ThemeContext<T extends Theme> {
6664 ) : [ T , Dispatch < SetStateAction < T > > ] {
6765 const [ theme , setTheme ] = this . use ( )
6866 useLayoutEffect ( ( ) => {
69- Object . keys ( theme ) . forEach ( key => {
70- element . style . setProperty ( `--${ kebabCase ( key ) } ` , theme [
71- key
72- ] as string )
73- } )
67+ Object . keys ( theme ) . forEach ( setProp )
7468 } , [ theme ] )
7569 return [ theme , setTheme ]
70+ function setProp ( key : string ) {
71+ element . style . setProperty (
72+ `--${ kebabCase ( key ) } ` ,
73+ ( theme as Record < string , string > ) [ key ] ,
74+ )
75+ }
7676 }
7777
7878 /**
You can’t perform that action at this time.
0 commit comments