-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f3fbf8
commit 58ecb41
Showing
3 changed files
with
15 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,5 +52,5 @@ export { | |
useScrollToTop, | ||
useHash, | ||
useSpeech, | ||
useProvidersTree | ||
useProvidersTree, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import * as React from 'react'; | ||
|
||
export default function useProvidersTree() { | ||
|
||
const buildProviders = (componentsWithProps: any) => { | ||
const initialComponent = ({ children }: any) => <>{children}</>; | ||
|
||
return componentsWithProps.reduce((AccumulatedComponents: any, [Provider, props = {}]: any) => { | ||
return ({ children }: any) => { | ||
return <AccumulatedComponents> | ||
<Provider {...props}>{children}</Provider> | ||
</AccumulatedComponents> | ||
} | ||
}, initialComponent); | ||
} | ||
return componentsWithProps.reduce( | ||
(AccumulatedComponents: any, [Provider, props = {}]: any) => { | ||
return ({ children }: any) => { | ||
return ( | ||
<AccumulatedComponents> | ||
<Provider {...props}>{children}</Provider> | ||
</AccumulatedComponents> | ||
); | ||
}; | ||
}, | ||
initialComponent | ||
); | ||
}; | ||
|
||
return buildProviders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters