@proedis/react 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/cjs/hooks/useAutoControlledState.js +69 -69
  2. package/cjs/hooks/useClickOutside.js +54 -54
  3. package/cjs/hooks/useDataManager.js +29 -29
  4. package/cjs/hooks/useDataSelector.js +76 -76
  5. package/cjs/hooks/useDebouncedCallback.js +34 -34
  6. package/cjs/hooks/useElementType.js +35 -35
  7. package/cjs/hooks/useEnhancedEffect.js +8 -8
  8. package/cjs/hooks/useEvent.js +37 -37
  9. package/cjs/hooks/useForkRef.js +16 -16
  10. package/cjs/hooks/useInputValue.js +15 -15
  11. package/cjs/hooks/useObjectState.js +37 -37
  12. package/cjs/hooks/useSafeState.js +27 -27
  13. package/cjs/hooks/useSyncedRef.js +16 -16
  14. package/cjs/hooks/useUnmountEffect.js +14 -14
  15. package/cjs/hooks/useWindowSize.js +54 -54
  16. package/cjs/index.js +0 -4
  17. package/cjs/utils/compose.js +40 -40
  18. package/cjs/utils/contextBuilder.js +36 -36
  19. package/cjs/utils/shorthands.js +148 -148
  20. package/esm/hooks/useAutoControlledState.js +69 -69
  21. package/esm/hooks/useClickOutside.js +54 -54
  22. package/esm/hooks/useDataManager.js +29 -29
  23. package/esm/hooks/useDataSelector.js +76 -76
  24. package/esm/hooks/useDebouncedCallback.js +34 -34
  25. package/esm/hooks/useElementType.js +35 -35
  26. package/esm/hooks/useEnhancedEffect.js +8 -8
  27. package/esm/hooks/useEvent.js +37 -37
  28. package/esm/hooks/useForkRef.js +16 -16
  29. package/esm/hooks/useInputValue.js +15 -15
  30. package/esm/hooks/useObjectState.js +37 -37
  31. package/esm/hooks/useSafeState.js +27 -27
  32. package/esm/hooks/useSyncedRef.js +16 -16
  33. package/esm/hooks/useUnmountEffect.js +14 -14
  34. package/esm/hooks/useWindowSize.js +54 -54
  35. package/esm/index.js +0 -2
  36. package/esm/utils/compose.js +40 -40
  37. package/esm/utils/contextBuilder.js +36 -36
  38. package/esm/utils/shorthands.js +148 -148
  39. package/package.json +19 -21
  40. package/tsconfig.declaration.tsbuildinfo +1 -1
  41. package/types/hooks/index.d.ts +0 -2
  42. package/types/utils/shorthands.d.ts +1 -1
  43. package/cjs/hooks/useQueryString.js +0 -92
  44. package/cjs/hooks/useQueryStringValue.js +0 -50
  45. package/esm/hooks/useQueryString.js +0 -70
  46. package/esm/hooks/useQueryStringValue.js +0 -29
  47. package/types/hooks/useQueryString.d.ts +0 -22
  48. package/types/hooks/useQueryStringValue.d.ts +0 -8
@@ -3,43 +3,43 @@
3
3
  var useEnhancedEffect = require('./useEnhancedEffect.js');
4
4
  var useSyncedRef = require('./useSyncedRef.js');
5
5
 
6
- /**
7
- * Attach a HTMLElement lister to a target DOM Element.
8
- *
9
- * @param name The event to listen to
10
- * @param callback The callback function to call
11
- * @param options Some options to customize the hook
12
- */
13
- function useEvent(name, callback, options) {
14
- /** Get options and set defaults */
15
- const { disabled = false, target = document.documentElement } = options || {};
16
- /**
17
- * Every time the hook will be called update the handler
18
- * function in the ref object.
19
- * This logic will help the event listener to get the last
20
- * version update of the handler, without having the need to save it
21
- * into react use effect dependencies
22
- */
23
- const handler = useSyncedRef.useSyncedRef(callback);
24
- useEnhancedEffect.useEnhancedEffect(() => {
25
- /** If hook has been disabled, avoid the event listen */
26
- if (disabled) {
27
- return;
28
- }
29
- /**
30
- * Wrap the handler function into a local scoped function to be removed
31
- * once the effect will be cleared.
32
- * HEADS UP, using the useRef method to save the handler; the function
33
- * could not be the same reference as the component mount
34
- */
35
- const eventCallback = (event) => (handler.current.apply(target, [event]));
36
- /** Attach the event listener to the DOM target */
37
- target.addEventListener(name, eventCallback);
38
- /** On effect clear, remove the event attached to the target */
39
- return () => {
40
- target.removeEventListener(name, eventCallback);
41
- };
42
- }, [disabled, name, target, handler]);
6
+ /**
7
+ * Attach a HTMLElement lister to a target DOM Element.
8
+ *
9
+ * @param name The event to listen to
10
+ * @param callback The callback function to call
11
+ * @param options Some options to customize the hook
12
+ */
13
+ function useEvent(name, callback, options) {
14
+ /** Get options and set defaults */
15
+ const { disabled = false, target = document.documentElement } = options || {};
16
+ /**
17
+ * Every time the hook will be called update the handler
18
+ * function in the ref object.
19
+ * This logic will help the event listener to get the last
20
+ * version update of the handler, without having the need to save it
21
+ * into react use effect dependencies
22
+ */
23
+ const handler = useSyncedRef.useSyncedRef(callback);
24
+ useEnhancedEffect.useEnhancedEffect(() => {
25
+ /** If hook has been disabled, avoid the event listen */
26
+ if (disabled) {
27
+ return;
28
+ }
29
+ /**
30
+ * Wrap the handler function into a local scoped function to be removed
31
+ * once the effect will be cleared.
32
+ * HEADS UP, using the useRef method to save the handler; the function
33
+ * could not be the same reference as the component mount
34
+ */
35
+ const eventCallback = (event) => (handler.current.apply(target, [event]));
36
+ /** Attach the event listener to the DOM target */
37
+ target.addEventListener(name, eventCallback);
38
+ /** On effect clear, remove the event attached to the target */
39
+ return () => {
40
+ target.removeEventListener(name, eventCallback);
41
+ };
42
+ }, [disabled, name, target, handler]);
43
43
  }
44
44
 
45
45
  exports.useEvent = useEvent;
@@ -21,22 +21,22 @@ function _interopNamespaceDefault(e) {
21
21
 
22
22
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
23
 
24
- /**
25
- * Group multiple ref object into a single ref that will
26
- * assign the referenced element to each single ref.
27
- *
28
- * @param refs
29
- */
30
- function useForkRef(...refs) {
31
- return React__namespace.useCallback((refValue) => {
32
- refs.forEach((ref) => ref.current = refValue ?? undefined);
33
- },
34
- // react-hooks/exhaustive-deps will warn the next line because
35
- // the array will always change at each call of the hook.
36
- // In this case, could disable the warning because the ref hook used
37
- // as arguments won't change, because ref objects are immutable
38
- // eslint-disable-next-line react-hooks/exhaustive-deps
39
- [...refs]);
24
+ /**
25
+ * Group multiple ref object into a single ref that will
26
+ * assign the referenced element to each single ref.
27
+ *
28
+ * @param refs
29
+ */
30
+ function useForkRef(...refs) {
31
+ return React__namespace.useCallback((refValue) => {
32
+ refs.forEach((ref) => ref.current = refValue ?? undefined);
33
+ },
34
+ // react-hooks/exhaustive-deps will warn the next line because
35
+ // the array will always change at each call of the hook.
36
+ // In this case, could disable the warning because the ref hook used
37
+ // as arguments won't change, because ref objects are immutable
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ [...refs]);
40
40
  }
41
41
 
42
42
  exports.useForkRef = useForkRef;
@@ -21,21 +21,21 @@ function _interopNamespaceDefault(e) {
21
21
 
22
22
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
23
 
24
- function useInputValue(initialValue) {
25
- // ----
26
- // Internal Hooks
27
- // ----
28
- const [value, setValue] = React__namespace.useState(initialValue ?? '');
29
- // ----
30
- // Handler
31
- // ----
32
- const handleInputValueChange = React__namespace.useCallback((event) => {
33
- setValue(event.currentTarget.value);
34
- }, []);
35
- // ----
36
- // Hook Returns
37
- // ----
38
- return [value, handleInputValueChange, setValue];
24
+ function useInputValue(initialValue) {
25
+ // ----
26
+ // Internal Hooks
27
+ // ----
28
+ const [value, setValue] = React__namespace.useState(initialValue ?? '');
29
+ // ----
30
+ // Handler
31
+ // ----
32
+ const handleInputValueChange = React__namespace.useCallback((event) => {
33
+ setValue(event.currentTarget.value);
34
+ }, []);
35
+ // ----
36
+ // Hook Returns
37
+ // ----
38
+ return [value, handleInputValueChange, setValue];
39
39
  }
40
40
 
41
41
  exports.useInputValue = useInputValue;
@@ -24,43 +24,43 @@ function _interopNamespaceDefault(e) {
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- /**
28
- * Hook that could be used to manage an immutable object, updating or returning value
29
- * using key dotted path.
30
- *
31
- * @param initialObject
32
- * @param options
33
- */
34
- function useObjectState(initialObject, options) {
35
- /** Create the initial state using provided object */
36
- const [state, setState] = useSafeState.useSafeState(initialObject);
37
- /** Call the onChange function every time state changes */
38
- const onStateChangeRef = useSyncedRef.useSyncedRef(options?.onChange);
39
- React__namespace.useEffect(() => {
40
- const { current: currentOnChange } = onStateChangeRef;
41
- if (typeof currentOnChange === 'function') {
42
- currentOnChange(state);
43
- }
44
- }, [onStateChangeRef, state]);
45
- /** Create the utilities to instantly transact the state */
46
- const transact = React__namespace.useCallback((nextState) => {
47
- if (typeof nextState === 'function') {
48
- setState((curr) => ({
49
- ...nextState(curr)
50
- }));
51
- }
52
- else {
53
- setState({ ...nextState });
54
- }
55
- }, [setState]);
56
- /** Create the utility to get the value at specific path */
57
- const getValue = React__namespace.useCallback((path) => (utils.getValueAt(state, path)), [state]);
58
- /** Set value at specific path */
59
- const setValue = React__namespace.useCallback((path, value) => {
60
- setState((curr) => (utils.setValueAt(curr, path, value, { immutable: true })));
61
- }, [setState]);
62
- /** Hook returns */
63
- return [state, { getValue, setValue, transact }];
27
+ /**
28
+ * Hook that could be used to manage an immutable object, updating or returning value
29
+ * using key dotted path.
30
+ *
31
+ * @param initialObject
32
+ * @param options
33
+ */
34
+ function useObjectState(initialObject, options) {
35
+ /** Create the initial state using provided object */
36
+ const [state, setState] = useSafeState.useSafeState(initialObject);
37
+ /** Call the onChange function every time state changes */
38
+ const onStateChangeRef = useSyncedRef.useSyncedRef(options?.onChange);
39
+ React__namespace.useEffect(() => {
40
+ const { current: currentOnChange } = onStateChangeRef;
41
+ if (typeof currentOnChange === 'function') {
42
+ currentOnChange(state);
43
+ }
44
+ }, [onStateChangeRef, state]);
45
+ /** Create the utilities to instantly transact the state */
46
+ const transact = React__namespace.useCallback((nextState) => {
47
+ if (typeof nextState === 'function') {
48
+ setState((curr) => ({
49
+ ...nextState(curr)
50
+ }));
51
+ }
52
+ else {
53
+ setState({ ...nextState });
54
+ }
55
+ }, [setState]);
56
+ /** Create the utility to get the value at specific path */
57
+ const getValue = React__namespace.useCallback((path) => (utils.getValueAt(state, path)), [state]);
58
+ /** Set value at specific path */
59
+ const setValue = React__namespace.useCallback((path, value) => {
60
+ setState((curr) => (utils.setValueAt(curr, path, value, { immutable: true })));
61
+ }, [setState]);
62
+ /** Hook returns */
63
+ return [state, { getValue, setValue, transact }];
64
64
  }
65
65
 
66
66
  exports.useObjectState = useObjectState;
@@ -22,33 +22,33 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
24
24
 
25
- /**
26
- * Hook that could be used to wrap the original
27
- * setState hook function to be called and to change
28
- * state only if the using component is mounted
29
- *
30
- * @param initialState Initial state to use
31
- */
32
- function useSafeState(initialState) {
33
- /** Init internal state using default React hook */
34
- const [state, setState] = React__namespace.useState(initialState);
35
- /** Use a ref hook to check component mount */
36
- const isMounted = React__namespace.useRef(false);
37
- /** Update the ref on component mount/unmount */
38
- useEnhancedEffect.useEnhancedEffect(() => {
39
- isMounted.current = true;
40
- return () => {
41
- isMounted.current = false;
42
- };
43
- }, []);
44
- /** Wrap original setState action to consider mounted state */
45
- const wrappedSeState = React__namespace.useCallback((newState) => {
46
- if (isMounted.current) {
47
- setState(newState);
48
- }
49
- }, []);
50
- /** Return state and wrapped set state */
51
- return [state, wrappedSeState];
25
+ /**
26
+ * Hook that could be used to wrap the original
27
+ * setState hook function to be called and to change
28
+ * state only if the using component is mounted
29
+ *
30
+ * @param initialState Initial state to use
31
+ */
32
+ function useSafeState(initialState) {
33
+ /** Init internal state using default React hook */
34
+ const [state, setState] = React__namespace.useState(initialState);
35
+ /** Use a ref hook to check component mount */
36
+ const isMounted = React__namespace.useRef(false);
37
+ /** Update the ref on component mount/unmount */
38
+ useEnhancedEffect.useEnhancedEffect(() => {
39
+ isMounted.current = true;
40
+ return () => {
41
+ isMounted.current = false;
42
+ };
43
+ }, []);
44
+ /** Wrap original setState action to consider mounted state */
45
+ const wrappedSeState = React__namespace.useCallback((newState) => {
46
+ if (isMounted.current) {
47
+ setState(newState);
48
+ }
49
+ }, []);
50
+ /** Return state and wrapped set state */
51
+ return [state, wrappedSeState];
52
52
  }
53
53
 
54
54
  exports.useSafeState = useSafeState;
@@ -21,22 +21,22 @@ function _interopNamespaceDefault(e) {
21
21
 
22
22
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
23
 
24
- /**
25
- * An augmented version of the useRef function.
26
- * It will return a 'ref' style object with the
27
- * current key memoized, returning each time
28
- * the most updated version of the value
29
- *
30
- * @param value The value to store into ref object
31
- */
32
- function useSyncedRef(value) {
33
- const ref = React__namespace.useRef(value);
34
- ref.current = value;
35
- return React__namespace.useMemo(() => Object.freeze({
36
- get current() {
37
- return ref.current;
38
- }
39
- }), []);
24
+ /**
25
+ * An augmented version of the useRef function.
26
+ * It will return a 'ref' style object with the
27
+ * current key memoized, returning each time
28
+ * the most updated version of the value
29
+ *
30
+ * @param value The value to store into ref object
31
+ */
32
+ function useSyncedRef(value) {
33
+ const ref = React__namespace.useRef(value);
34
+ ref.current = value;
35
+ return React__namespace.useMemo(() => Object.freeze({
36
+ get current() {
37
+ return ref.current;
38
+ }
39
+ }), []);
40
40
  }
41
41
 
42
42
  exports.useSyncedRef = useSyncedRef;
@@ -3,20 +3,20 @@
3
3
  var useEnhancedEffect = require('./useEnhancedEffect.js');
4
4
  var useSyncedRef = require('./useSyncedRef.js');
5
5
 
6
- /**
7
- * Use this hook to call the provided
8
- * callable function to be called once the
9
- * component will unmount
10
- *
11
- * @param callback Function to be called
12
- */
13
- function useUnmountEffect(callback) {
14
- /** Save the callback function into an immutable object */
15
- const unmountCallback = useSyncedRef.useSyncedRef(callback);
16
- /** Attach an event to call function on unmount */
17
- useEnhancedEffect.useEnhancedEffect(() => () => {
18
- unmountCallback.current();
19
- }, [unmountCallback]);
6
+ /**
7
+ * Use this hook to call the provided
8
+ * callable function to be called once the
9
+ * component will unmount
10
+ *
11
+ * @param callback Function to be called
12
+ */
13
+ function useUnmountEffect(callback) {
14
+ /** Save the callback function into an immutable object */
15
+ const unmountCallback = useSyncedRef.useSyncedRef(callback);
16
+ /** Attach an event to call function on unmount */
17
+ useEnhancedEffect.useEnhancedEffect(() => () => {
18
+ unmountCallback.current();
19
+ }, [unmountCallback]);
20
20
  }
21
21
 
22
22
  exports.useUnmountEffect = useUnmountEffect;
@@ -22,60 +22,60 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
24
24
 
25
- /**
26
- * Monitor the change of the Window Size.
27
- * Take careful that the object returned by the hook will never change:
28
- * to use value within hook dependencies must deconstruct internal properties
29
- *
30
- * @param options Set hook options
31
- *
32
- * @example
33
- * // Do this
34
- * const { height, width } = useWindowSize();
35
- *
36
- * React.useEffect(
37
- * () => {
38
- * // Wonderful code...
39
- * },
40
- * [ height, width ]
41
- * );
42
- */
43
- function useWindowSize(options) {
44
- const { disabled } = options || {};
45
- // ----
46
- // Internal State
47
- // ----
48
- const [currentSize, setCurrentSize] = React__namespace.useState(() => ({
49
- height: typeof window !== 'undefined' ? window.innerHeight : 0,
50
- width: typeof window !== 'undefined' ? window.innerWidth : 0
51
- }));
52
- // ----
53
- // Handler
54
- // ----
55
- const handleWindowSizeChange = React__namespace.useCallback(() => setCurrentSize((curr) => {
56
- curr.height = window.innerHeight;
57
- curr.width = window.innerWidth;
58
- return curr;
59
- }), []);
60
- // ----
61
- // Internal Hooks
62
- // ----
63
- useEnhancedEffect.useEnhancedEffect(() => {
64
- /** If hook has been disabled, avoid the event listen */
65
- if (disabled) {
66
- return;
67
- }
68
- /** Attach event to the window element to listen for resize change */
69
- window.addEventListener('resize', handleWindowSizeChange);
70
- /** On effect clear, remove the event attached to the window */
71
- return () => {
72
- window.removeEventListener('resize', handleWindowSizeChange);
73
- };
74
- }, [disabled, handleWindowSizeChange]);
75
- // ----
76
- // Hook returns
77
- // ----
78
- return currentSize;
25
+ /**
26
+ * Monitor the change of the Window Size.
27
+ * Take careful that the object returned by the hook will never change:
28
+ * to use value within hook dependencies must deconstruct internal properties
29
+ *
30
+ * @param options Set hook options
31
+ *
32
+ * @example
33
+ * // Do this
34
+ * const { height, width } = useWindowSize();
35
+ *
36
+ * React.useEffect(
37
+ * () => {
38
+ * // Wonderful code...
39
+ * },
40
+ * [ height, width ]
41
+ * );
42
+ */
43
+ function useWindowSize(options) {
44
+ const { disabled } = options || {};
45
+ // ----
46
+ // Internal State
47
+ // ----
48
+ const [currentSize, setCurrentSize] = React__namespace.useState(() => ({
49
+ height: typeof window !== 'undefined' ? window.innerHeight : 0,
50
+ width: typeof window !== 'undefined' ? window.innerWidth : 0
51
+ }));
52
+ // ----
53
+ // Handler
54
+ // ----
55
+ const handleWindowSizeChange = React__namespace.useCallback(() => setCurrentSize((curr) => {
56
+ curr.height = window.innerHeight;
57
+ curr.width = window.innerWidth;
58
+ return curr;
59
+ }), []);
60
+ // ----
61
+ // Internal Hooks
62
+ // ----
63
+ useEnhancedEffect.useEnhancedEffect(() => {
64
+ /** If hook has been disabled, avoid the event listen */
65
+ if (disabled) {
66
+ return;
67
+ }
68
+ /** Attach event to the window element to listen for resize change */
69
+ window.addEventListener('resize', handleWindowSizeChange);
70
+ /** On effect clear, remove the event attached to the window */
71
+ return () => {
72
+ window.removeEventListener('resize', handleWindowSizeChange);
73
+ };
74
+ }, [disabled, handleWindowSizeChange]);
75
+ // ----
76
+ // Hook returns
77
+ // ----
78
+ return currentSize;
79
79
  }
80
80
 
81
81
  exports.useWindowSize = useWindowSize;
package/cjs/index.js CHANGED
@@ -11,8 +11,6 @@ var useEvent = require('./hooks/useEvent.js');
11
11
  var useForkRef = require('./hooks/useForkRef.js');
12
12
  var useInputValue = require('./hooks/useInputValue.js');
13
13
  var useObjectState = require('./hooks/useObjectState.js');
14
- var useQueryString = require('./hooks/useQueryString.js');
15
- var useQueryStringValue = require('./hooks/useQueryStringValue.js');
16
14
  var useSafeState = require('./hooks/useSafeState.js');
17
15
  var useSyncedRef = require('./hooks/useSyncedRef.js');
18
16
  var useUnmountEffect = require('./hooks/useUnmountEffect.js');
@@ -34,8 +32,6 @@ exports.useEvent = useEvent.useEvent;
34
32
  exports.useForkRef = useForkRef.useForkRef;
35
33
  exports.useInputValue = useInputValue.useInputValue;
36
34
  exports.useObjectState = useObjectState.useObjectState;
37
- exports.useQueryString = useQueryString.useQueryString;
38
- exports.useQueryStringValue = useQueryStringValue.useQueryStringValue;
39
35
  exports.useSafeState = useSafeState.useSafeState;
40
36
  exports.useSyncedRef = useSyncedRef.useSyncedRef;
41
37
  exports.useUnmountEffect = useUnmountEffect.useUnmountEffect;
@@ -22,46 +22,46 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
24
24
 
25
- /**
26
- * Return a single FunctionComponent, composed by nesting all components provided as arguments
27
- * from the first one (root component) to the last one (last inner component).
28
- * It is useful to avoid hell-nesting components declaration.
29
- *
30
- * @example
31
- * const Providers = compose(FirstProvider, SecondProvider, 'div', LastProvider);
32
- *
33
- * // Later
34
- * <Providers>
35
- * <MyApp />
36
- * </Providers>
37
- *
38
- * // Will Become
39
- * <FirstProvider>
40
- * <SecondProvider>
41
- * <div>
42
- * <LastProvider>
43
- * <MyApp />
44
- * </LastProvider>
45
- * </div>
46
- * </SecondProvider>
47
- * </FirstProvider>
48
- *
49
- * @param components
50
- */
51
- function compose(...components) {
52
- const ComposedComponent = (props) => (jsxRuntime.jsx(React__namespace.Fragment, { children: components.reduceRight((children, Provider) => {
53
- /** Array has style of [ Component, props ] */
54
- if (Array.isArray(Provider)) {
55
- /** Split component and Props */
56
- const [Component, componentProps] = Provider;
57
- /** Return Component and inner children */
58
- return (jsxRuntime.jsx(Component, { ...componentProps, children: children }));
59
- }
60
- /** Render provider without props */
61
- return (jsxRuntime.jsx(Provider, { children: children }));
62
- }, props.children) }));
63
- ComposedComponent.displayName = 'ComposedComponent';
64
- return ComposedComponent;
25
+ /**
26
+ * Return a single FunctionComponent, composed by nesting all components provided as arguments
27
+ * from the first one (root component) to the last one (last inner component).
28
+ * It is useful to avoid hell-nesting components declaration.
29
+ *
30
+ * @example
31
+ * const Providers = compose(FirstProvider, SecondProvider, 'div', LastProvider);
32
+ *
33
+ * // Later
34
+ * <Providers>
35
+ * <MyApp />
36
+ * </Providers>
37
+ *
38
+ * // Will Become
39
+ * <FirstProvider>
40
+ * <SecondProvider>
41
+ * <div>
42
+ * <LastProvider>
43
+ * <MyApp />
44
+ * </LastProvider>
45
+ * </div>
46
+ * </SecondProvider>
47
+ * </FirstProvider>
48
+ *
49
+ * @param components
50
+ */
51
+ function compose(...components) {
52
+ const ComposedComponent = (props) => (jsxRuntime.jsx(React__namespace.Fragment, { children: components.reduceRight((children, Provider) => {
53
+ /** Array has style of [ Component, props ] */
54
+ if (Array.isArray(Provider)) {
55
+ /** Split component and Props */
56
+ const [Component, componentProps] = Provider;
57
+ /** Return Component and inner children */
58
+ return (jsxRuntime.jsx(Component, { ...componentProps, children: children }));
59
+ }
60
+ /** Render provider without props */
61
+ return (jsxRuntime.jsx(Provider, { children: children }));
62
+ }, props.children) }));
63
+ ComposedComponent.displayName = 'ComposedComponent';
64
+ return ComposedComponent;
65
65
  }
66
66
 
67
67
  exports.compose = compose;