Skip to content

Commit 57c0273

Browse files
committed
feat(UpdatePet): refactor form structure for better readability and maintainability
chore(index.ts): remove unnecessary whitespace for cleaner code formatting
1 parent 7c49df0 commit 57c0273

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed

examples/hooks/src/components/UpdatePet.tsx

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,54 @@ export const UpdatePetForm = ({
5151

5252
return (
5353
<div className="update-pet">
54+
<form onSubmit={handleSubmit}>
55+
<div>
56+
<label htmlFor="name">Pet Name:</label>
57+
<input
58+
type="text"
59+
id="name"
60+
name="name"
61+
value={formData.name}
62+
onChange={handleInputChange}
63+
required
64+
/>
65+
</div>
5466

67+
<div>
68+
<label htmlFor="status">Status:</label>
69+
<select id="status" name="status" value={formData.status} onChange={handleInputChange}>
70+
<option value="available">Available</option>
71+
<option value="pending">Pending</option>
72+
<option value="sold">Sold</option>
73+
</select>
74+
</div>
5575

56-
<form onSubmit={handleSubmit}>
57-
<div>
58-
<label htmlFor="name">Pet Name:</label>
59-
<input
60-
type="text"
61-
id="name"
62-
name="name"
63-
value={formData.name}
64-
onChange={handleInputChange}
65-
required
66-
/>
67-
</div>
68-
69-
<div>
70-
<label htmlFor="status">Status:</label>
71-
<select id="status" name="status" value={formData.status} onChange={handleInputChange}>
72-
<option value="available">Available</option>
73-
<option value="pending">Pending</option>
74-
<option value="sold">Sold</option>
75-
</select>
76-
</div>
77-
78-
<div>
79-
<label htmlFor="photoUrls">Photo URL:</label>
80-
<input
81-
type="url"
82-
id="photoUrls"
83-
name="photoUrls"
84-
value={formData.photoUrls[0]}
85-
onChange={(e) =>
86-
setFormData((prev) => ({
87-
...prev,
88-
photoUrls: [e.target.value],
89-
}))
90-
}
91-
/>
92-
</div>
76+
<div>
77+
<label htmlFor="photoUrls">Photo URL:</label>
78+
<input
79+
type="url"
80+
id="photoUrls"
81+
name="photoUrls"
82+
value={formData.photoUrls[0]}
83+
onChange={(e) =>
84+
setFormData((prev) => ({
85+
...prev,
86+
photoUrls: [e.target.value],
87+
}))
88+
}
89+
/>
90+
</div>
9391

94-
<button type="submit" disabled={isPending}>
95-
{isPending ? "Updating..." : "Update Pet"}
96-
</button>
92+
<button type="submit" disabled={isPending}>
93+
{isPending ? "Updating..." : "Update Pet"}
94+
</button>
9795

98-
{isError && (
99-
<div style={{ color: "red", marginTop: "10px" }}>
100-
Error: {error?.message || "Failed to update pet"}
101-
</div>
102-
)}
103-
</form>
96+
{isError && (
97+
<div style={{ color: "red", marginTop: "10px" }}>
98+
Error: {error?.message || "Failed to update pet"}
99+
</div>
100+
)}
101+
</form>
104102
</div>
105103
);
106104
};

packages/hooks/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function createHooks<const T extends Operations>(
138138

139139
const hookName = toCamelCaseHookName(operationId);
140140
const typedOperation = operation as Operation;
141-
141+
142142
if (typedOperation.method === "get") {
143143
hooks[hookName] = (params?: any, queryOptions?: any) => {
144144
const queryKey = generateQueryKey(apiName, operationId, operation, params);

0 commit comments

Comments
 (0)