File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export default function buildContext < P , V > ( {
4
+ defaultValue = { } as V ,
5
+ useContextValue
6
+ } : {
7
+ defaultValue ?: V ;
8
+ useContextValue : ( p : P ) => V ;
9
+ } ) {
10
+ const Context = React . createContext ( defaultValue ) ;
11
+
12
+ function useContext ( ) {
13
+ return React . useContext ( Context ) ;
14
+ }
15
+
16
+ function ContextProvider ( {
17
+ children,
18
+ contextValueParameters = undefined as P
19
+ } : React . PropsWithChildren < {
20
+ contextValueParameters : P ;
21
+ } > ) {
22
+ const value = useContextValue ( contextValueParameters ) ;
23
+
24
+ if ( value === undefined ) {
25
+ return null ;
26
+ }
27
+
28
+ return < Context . Provider value = { value } > { children } </ Context . Provider > ;
29
+ }
30
+
31
+ return { useContext, ContextProvider} ;
32
+ }
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import buildContext from '~/components/jsx-helpers/build-context' ;
2
+ import buildContext from '~/components/jsx-helpers/build-context-ts ' ;
3
3
4
4
function useContextValue ( { prefix} = { prefix : 'menulabel' } ) {
5
5
const [ activeDropdown , setActiveDropdown ] = React . useState ( { } ) ;
You can’t perform that action at this time.
0 commit comments