@modhamanish/rn-mm-template 1.0.3 → 1.0.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/MMTemplate/README.md +53 -0
- package/MMTemplate/package.json +2 -2
- package/README.md +34 -0
- package/package.json +1 -1
package/MMTemplate/README.md
CHANGED
|
@@ -33,11 +33,64 @@ src/
|
|
|
33
33
|
├── mock/ # Mock data for testing and development
|
|
34
34
|
├── navigation/ # Navigation configuration (Stacks, Stacks, etc.)
|
|
35
35
|
├── screens/ # Screen components (Views)
|
|
36
|
+
├── services/ # Data fetching and API services (React Query)
|
|
36
37
|
├── theme/ # Theme configuration (Colors, Typography, Spacing)
|
|
37
38
|
├── types/ # Global TypeScript types and interfaces
|
|
38
39
|
└── utils/ # Helper functions and utilities
|
|
39
40
|
```
|
|
40
41
|
|
|
42
|
+
### Key Files & Directories
|
|
43
|
+
|
|
44
|
+
| Directory / File | Path | Description |
|
|
45
|
+
| :--- | :--- | :--- |
|
|
46
|
+
| **`assets/`** | `src/assets/` | Stores static assets such as images, fonts, and icons. |
|
|
47
|
+
| **`components/`** | `src/components/` | Contains reusable UI components used throughout the application. |
|
|
48
|
+
| **`context/`** | `src/context/` | Holds React Context definitions for global state management. |
|
|
49
|
+
| **`locales/`** | `src/locales/` | Contains translation files for internationalization. |
|
|
50
|
+
| **`mock/`** | `src/mock/` | Stores mock data used for development and testing. |
|
|
51
|
+
| **`navigation/`** | `src/navigation/` | Contains all navigation-related configuration. |
|
|
52
|
+
| **`screens/`** | `src/screens/` | Contains all the screen components (pages) of the application. |
|
|
53
|
+
| **`services/`** | `src/services/` | Data fetching layer using **React Query** and **Axios**. |
|
|
54
|
+
| **`theme/`** | `src/theme/` | Centralized theme configuration (e.g., Colors, Typography). |
|
|
55
|
+
| **`types/`** | `src/types/` | Stores TypeScript type definitions and interfaces. |
|
|
56
|
+
| **`utils/`** | `src/utils/` | Contains utility functions and helper classes. |
|
|
57
|
+
|
|
58
|
+
Navigation automatically switches between these stacks based on the `user` state in `AuthContext`.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🚀 Data Fetching (React Query)
|
|
63
|
+
|
|
64
|
+
MMTemplate uses **TanStack Query (React Query) v5** for server state management and **Axios** for API requests.
|
|
65
|
+
|
|
66
|
+
### 1. Services Structure
|
|
67
|
+
- **`axiosInstance.ts`**: Configured Axios instance with base URL and interceptors.
|
|
68
|
+
- **`queryKeys.ts`**: Centralized keys for consistency and easy invalidation.
|
|
69
|
+
- **`*.query.ts`**: Feature-specific hooks for fetching and mutating data.
|
|
70
|
+
|
|
71
|
+
### 2. Usage Example
|
|
72
|
+
To fetch data, use a query hook defined in `src/services`:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useGetNotesQuery } from '../services/note.query';
|
|
76
|
+
|
|
77
|
+
const { data, isLoading, error } = useGetNotesQuery();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To update data, use a mutation hook:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { useAddNoteMutation } from '../services/note.query';
|
|
84
|
+
|
|
85
|
+
const { mutate, isPending } = useAddNoteMutation();
|
|
86
|
+
const handleSave = () => mutate({ title: 'New Note', content: '...' });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Global Configuration
|
|
90
|
+
The `QueryClient` is pre-configured in `App.tsx` with optimized defaults (e.g., `refetchOnWindowFocus: false`).
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
41
94
|
## 🛠 Prerequisites
|
|
42
95
|
|
|
43
96
|
Before you begin, ensure you have the following installed on your machine:
|
package/MMTemplate/package.json
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"react-i18next": "^16.5.1",
|
|
23
23
|
"react-native": "0.83.1",
|
|
24
24
|
"react-native-keyboard-controller": "^1.20.3",
|
|
25
|
-
"react-native-mmkv": "^4.1.
|
|
26
|
-
"react-native-nitro-modules": "^0.
|
|
25
|
+
"react-native-mmkv": "^4.1.2",
|
|
26
|
+
"react-native-nitro-modules": "^0.33.9",
|
|
27
27
|
"react-native-reanimated": "^4.2.1",
|
|
28
28
|
"react-native-safe-area-context": "^5.6.2",
|
|
29
29
|
"react-native-screens": "^4.19.0",
|
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ src/
|
|
|
43
43
|
├── mock/ # Mock data for testing and development
|
|
44
44
|
├── navigation/ # Navigation configuration (Stacks, Stacks, etc.)
|
|
45
45
|
├── screens/ # Screen components (Views)
|
|
46
|
+
├── services/ # Data fetching and API services (React Query)
|
|
46
47
|
├── theme/ # Theme configuration (Colors, Typography, Spacing)
|
|
47
48
|
├── types/ # Global TypeScript types and interfaces
|
|
48
49
|
└── utils/ # Helper functions and utilities
|
|
@@ -63,6 +64,7 @@ src/
|
|
|
63
64
|
| └ `AuthCheck.tsx` | `src/navigation/AuthCheck.tsx` | Entry splash screen logic. Determines authentication state and routes accordingly. |
|
|
64
65
|
| └ `AuthStack.tsx` | `src/navigation/AuthStack.tsx` | Authentication flow stack. Defines screens like Login and Registration. |
|
|
65
66
|
| **`screens/`** | `src/screens/` | Contains all the screen components (pages) of the application. |
|
|
67
|
+
| **`services/`** | `src/services/` | Data fetching layer using **React Query** and **Axios**. Contains API hooks and instances. |
|
|
66
68
|
| **`theme/`** | `src/theme/` | Centralized theme configuration (e.g., Colors, Typography). |
|
|
67
69
|
| **`types/`** | `src/types/` | Stores TypeScript type definitions and interfaces for the application. |
|
|
68
70
|
| **`utils/`** | `src/utils/` | Contains utility functions and helper classes. |
|
|
@@ -95,6 +97,38 @@ User sessions are persisted locally using `react-native-mmkv`, ensuring users st
|
|
|
95
97
|
|
|
96
98
|
---
|
|
97
99
|
|
|
100
|
+
## 🚀 Data Fetching (React Query)
|
|
101
|
+
|
|
102
|
+
MMTemplate uses **TanStack Query (React Query) v5** for server state management and **Axios** for API requests.
|
|
103
|
+
|
|
104
|
+
### 1. Services Structure
|
|
105
|
+
- **`axiosInstance.ts`**: Configured Axios instance with base URL and interceptors.
|
|
106
|
+
- **`queryKeys.ts`**: Centralized keys for consistency and easy invalidation.
|
|
107
|
+
- **`*.query.ts`**: Feature-specific hooks for fetching and mutating data.
|
|
108
|
+
|
|
109
|
+
### 2. Usage Example
|
|
110
|
+
To fetch data, use a query hook defined in `src/services`:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { useGetNotesQuery } from '../services/note.query';
|
|
114
|
+
|
|
115
|
+
const { data, isLoading, error } = useGetNotesQuery();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
To update data, use a mutation hook:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import { useAddNoteMutation } from '../services/note.query';
|
|
122
|
+
|
|
123
|
+
const { mutate, isPending } = useAddNoteMutation();
|
|
124
|
+
const handleSave = () => mutate({ title: 'New Note', content: '...' });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 3. Global Configuration
|
|
128
|
+
The `QueryClient` is pre-configured in `App.tsx` with optimized defaults (e.g., `refetchOnWindowFocus: false`).
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
98
132
|
## 📝 Scripts
|
|
99
133
|
|
|
100
134
|
* `yarn start`: Starts the Metro Bundler.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modhamanish/rn-mm-template",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A robust and modern React Native template built with TypeScript, designed to jumpstart your mobile application development.",
|
|
5
5
|
"repository": "https://github.com/modhamanish/mm-template.git",
|
|
6
6
|
"author": "Manish Modha",
|