@@ -37,14 +37,19 @@ export type ItemContext = {
3737
3838const Context = React . createContext ( null as ItemContext | null ) ;
3939
40- class Provider extends React . Component < ProviderProps > {
41- toggleExpanded = ( ) : void => {
42- this . props . accordionContext . toggleExpanded ( this . props . uuid ) ;
40+ const Provider = ( {
41+ children,
42+ uuid,
43+ accordionContext,
44+ dangerouslySetExpanded,
45+ } : ProviderProps ) : JSX . Element => {
46+ const toggleExpanded = ( ) : void => {
47+ accordionContext . toggleExpanded ( uuid ) ;
4348 } ;
4449
45- renderChildren = ( accordionContext : AccordionContext ) : JSX . Element => {
46- const { uuid , dangerouslySetExpanded } = this . props ;
47-
50+ const renderChildren = (
51+ accordionContext : AccordionContext ,
52+ ) : JSX . Element => {
4853 const expanded =
4954 dangerouslySetExpanded ?? accordionContext . isItemExpanded ( uuid ) ;
5055 const disabled = accordionContext . isItemDisabled ( uuid ) ;
@@ -64,25 +69,21 @@ class Provider extends React.Component<ProviderProps> {
6469 uuid,
6570 expanded,
6671 disabled,
67- toggleExpanded : this . toggleExpanded ,
72+ toggleExpanded : toggleExpanded ,
6873 panelAttributes,
6974 headingAttributes,
7075 buttonAttributes,
7176 } }
7277 >
73- { this . props . children }
78+ { children }
7479 </ Context . Provider >
7580 ) ;
7681 } ;
7782
78- render ( ) : JSX . Element {
79- return (
80- < AccordionContextConsumer >
81- { this . renderChildren }
82- </ AccordionContextConsumer >
83- ) ;
84- }
85- }
83+ return (
84+ < AccordionContextConsumer > { renderChildren } </ AccordionContextConsumer >
85+ ) ;
86+ } ;
8687
8788const ProviderWrapper : React . SFC < ProviderWrapperProps > = (
8889 props : ProviderWrapperProps ,
@@ -100,12 +101,10 @@ type ConsumerProps = {
100101 children ( container : ItemContext ) : React . ReactNode ;
101102} ;
102103
103- export class Consumer extends React . PureComponent < ConsumerProps > {
104- renderChildren = ( container : ItemContext | null ) : React . ReactNode => {
105- return container ? this . props . children ( container ) : null ;
104+ export const Consumer = ( { children } : ConsumerProps ) : JSX . Element = > {
105+ const renderChildren = ( container : ItemContext | null ) : React . ReactNode => {
106+ return container ? children ( container ) : null ;
106107 } ;
107108
108- render ( ) : JSX . Element {
109- return < Context . Consumer > { this . renderChildren } </ Context . Consumer > ;
110- }
111- }
109+ return < Context . Consumer > { renderChildren } </ Context . Consumer > ;
110+ } ;
0 commit comments