@moamc/rn-cli 1.4.2 → 1.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moamc/rn-cli",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Enterprise-grade Code Generation CLI for React Native Applications",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -41,7 +41,7 @@ const generateHookTemplate = (hookName, hasForm = false, formFields = [], eventN
41
41
  const hasDropdown = formFields.some(f => f.type === 'dropdown');
42
42
  const hasDate = formFields.some(f => f.type === 'date');
43
43
 
44
- return `import { useState } from 'react';
44
+ return `import { useState, useCallback } from 'react';
45
45
  import { showToastNotification } from '../../../../helpers/common';${hasDate ? '\nimport moment from \'moment\';' : ''}
46
46
  import { validate${hookName} } from '../validation';
47
47
 
@@ -53,22 +53,21 @@ ${formFields.map(f => `\t\t${f.name}: '',`).join('\n')}
53
53
  \tconst [touched, setTouched] = useState({});
54
54
  \tconst [loading, setLoading] = useState(false);${hasDropdown ? '\n\tconst [bottomSheetType, setBottomSheetType] = useState(null);' : ''}${hasDate ? '\n\tconst [openCalendar, setOpenCalendar] = useState(false);' : ''}
55
55
 
56
- \tconst handleChange = (value, field) => {
57
- \t\tconst updatedFormData = { ...formData, [field]: value };
58
- \t\tsetFormData(updatedFormData);
56
+ \tconst handleChange = useCallback((value, field) => {
57
+ \t\tsetFormData(prev => ({ ...prev, [field]: value }));
59
58
  \t\tsetTouched(prev => ({ ...prev, [field]: true }));
60
59
  \t\t
61
- \t\t// Re-validate on change
62
- \t\tconst validationErrors = validate${hookName}(updatedFormData);
63
- \t\tsetErrors(validationErrors);
64
- \t};
60
+ \t\t// Clear error for this field on change
61
+ \t\tif (errors[field]) {
62
+ \t\t\tsetErrors(prev => ({ ...prev, [field]: undefined }));
63
+ \t\t}
64
+ \t}, [errors]);
65
65
 
66
- \tconst handleSubmit = async () => {
66
+ \tconst handleSubmit = useCallback(async () => {
67
67
  \t\tconst validationErrors = validate${hookName}(formData);
68
68
  \t\tif (Object.keys(validationErrors).length > 0) {
69
69
  \t\t\tsetErrors(validationErrors);
70
70
  \t\t\tsetTouched(Object.keys(formData).reduce((acc, key) => ({ ...acc, [key]: true }), {}));
71
- \t\t\t// Validation errors are shown inline below each field
72
71
  \t\t\treturn;
73
72
  \t\t}
74
73
 
@@ -81,11 +80,11 @@ ${formFields.map(f => `\t\t${f.name}: '',`).join('\n')}
81
80
  \t\t} finally {
82
81
  \t\t\tsetLoading(false);
83
82
  \t\t}
84
- \t};${hasDropdown ? `
83
+ \t}, [formData]);${hasDropdown ? `
85
84
 
86
- \tconst openBottomSheet = (type) => {
85
+ \tconst openBottomSheet = useCallback((type) => {
87
86
  \t\tsetBottomSheetType(type);
88
- \t};` : ''}
87
+ \t}, []);` : ''}
89
88
 
90
89
  \treturn {
91
90
  \t\tformData,