@react-pakistan/util-functions 1.24.3 → 1.24.4
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.
- package/index.d.ts +0 -1
- package/index.js +1 -1
- package/module/my-module.d.ts +0 -24
- package/module/my-module.js +69 -88
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -41,4 +41,4 @@ __exportStar(require("./general"), exports);
|
|
|
41
41
|
__exportStar(require("./hooks"), exports);
|
|
42
42
|
__exportStar(require("./local-storage"), exports);
|
|
43
43
|
__exportStar(require("./storybook"), exports);
|
|
44
|
-
|
|
44
|
+
// export * from './module/my-module';
|
package/module/my-module.d.ts
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
type State = {
|
|
3
|
-
count: number;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
};
|
|
6
|
-
type Action = {
|
|
7
|
-
type: 'INCREMENT';
|
|
8
|
-
} | {
|
|
9
|
-
type: 'DECREMENT';
|
|
10
|
-
} | {
|
|
11
|
-
type: 'SET_LOADING';
|
|
12
|
-
payload: boolean;
|
|
13
|
-
};
|
|
14
|
-
type MyModuleProviderProps = {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
initialState?: Partial<State>;
|
|
17
|
-
};
|
|
18
|
-
export declare const MyModuleProvider: React.FC<MyModuleProviderProps>;
|
|
19
|
-
export declare const useMyModule: () => {
|
|
20
|
-
state: State;
|
|
21
|
-
dispatch: React.Dispatch<Action>;
|
|
22
|
-
};
|
|
23
|
-
export declare const Counter: React.FC;
|
|
24
|
-
export {};
|
package/module/my-module.js
CHANGED
|
@@ -1,88 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
exports.MyModuleProvider = MyModuleProvider;
|
|
71
|
-
// 5. Custom hook to access the context
|
|
72
|
-
var useMyModule = function () {
|
|
73
|
-
var context = (0, react_1.useContext)(MyModuleContext);
|
|
74
|
-
if (context === undefined) {
|
|
75
|
-
throw new Error('useMyModule must be used within a MyModuleProvider');
|
|
76
|
-
}
|
|
77
|
-
return context;
|
|
78
|
-
};
|
|
79
|
-
exports.useMyModule = useMyModule;
|
|
80
|
-
// 6. Your actual module components
|
|
81
|
-
var Counter = function () {
|
|
82
|
-
var _a = (0, exports.useMyModule)(), state = _a.state, dispatch = _a.dispatch;
|
|
83
|
-
return (react_1.default.createElement("div", null,
|
|
84
|
-
react_1.default.createElement("button", { onClick: function () { return dispatch({ type: 'DECREMENT' }); } }, "-"),
|
|
85
|
-
react_1.default.createElement("span", null, state.count),
|
|
86
|
-
react_1.default.createElement("button", { onClick: function () { return dispatch({ type: 'INCREMENT' }); } }, "+")));
|
|
87
|
-
};
|
|
88
|
-
exports.Counter = Counter;
|
|
1
|
+
// /* eslint-disable */
|
|
2
|
+
// import React, { useReducer, createContext, useContext } from 'react';
|
|
3
|
+
// // 1. Define your state shape and actions
|
|
4
|
+
// type State = {
|
|
5
|
+
// // Your state properties here
|
|
6
|
+
// count: number;
|
|
7
|
+
// isLoading: boolean;
|
|
8
|
+
// };
|
|
9
|
+
// type Action =
|
|
10
|
+
// | { type: 'INCREMENT' }
|
|
11
|
+
// | { type: 'DECREMENT' }
|
|
12
|
+
// | { type: 'SET_LOADING'; payload: boolean };
|
|
13
|
+
// // 2. Create a context for your module
|
|
14
|
+
// const MyModuleContext = createContext<{
|
|
15
|
+
// state: State;
|
|
16
|
+
// dispatch: React.Dispatch<Action>;
|
|
17
|
+
// } | undefined>(undefined);
|
|
18
|
+
// // 3. Reducer function
|
|
19
|
+
// const reducer = (state: State, action: Action): State => {
|
|
20
|
+
// switch (action.type) {
|
|
21
|
+
// case 'INCREMENT':
|
|
22
|
+
// return { ...state, count: state.count + 1 };
|
|
23
|
+
// case 'DECREMENT':
|
|
24
|
+
// return { ...state, count: state.count - 1 };
|
|
25
|
+
// case 'SET_LOADING':
|
|
26
|
+
// return { ...state, isLoading: action.payload };
|
|
27
|
+
// default:
|
|
28
|
+
// return state;
|
|
29
|
+
// }
|
|
30
|
+
// };
|
|
31
|
+
// // 4. Provider component
|
|
32
|
+
// type MyModuleProviderProps = {
|
|
33
|
+
// children: React.ReactNode;
|
|
34
|
+
// initialState?: Partial<State>;
|
|
35
|
+
// };
|
|
36
|
+
// export const MyModuleProvider: React.FC<MyModuleProviderProps> = ({
|
|
37
|
+
// children,
|
|
38
|
+
// initialState,
|
|
39
|
+
// }) => {
|
|
40
|
+
// const [state, dispatch] = useReducer(reducer, {
|
|
41
|
+
// count: 0,
|
|
42
|
+
// isLoading: false,
|
|
43
|
+
// ...initialState,
|
|
44
|
+
// });
|
|
45
|
+
// return (
|
|
46
|
+
// <MyModuleContext.Provider value={{ state, dispatch }}>
|
|
47
|
+
// {children}
|
|
48
|
+
// </MyModuleContext.Provider>
|
|
49
|
+
// );
|
|
50
|
+
// };
|
|
51
|
+
// // 5. Custom hook to access the context
|
|
52
|
+
// export const useMyModule = () => {
|
|
53
|
+
// const context = useContext(MyModuleContext);
|
|
54
|
+
// if (context === undefined) {
|
|
55
|
+
// throw new Error('useMyModule must be used within a MyModuleProvider');
|
|
56
|
+
// }
|
|
57
|
+
// return context;
|
|
58
|
+
// };
|
|
59
|
+
// // 6. Your actual module components
|
|
60
|
+
// export const Counter: React.FC = () => {
|
|
61
|
+
// const { state, dispatch } = useMyModule();
|
|
62
|
+
// return (
|
|
63
|
+
// <div>
|
|
64
|
+
// <button onClick={() => dispatch({ type: 'DECREMENT' })}>-</button>
|
|
65
|
+
// <span>{state.count}</span>
|
|
66
|
+
// <button onClick={() => dispatch({ type: 'INCREMENT' })}>+</button>
|
|
67
|
+
// </div>
|
|
68
|
+
// );
|
|
69
|
+
// };
|