Skip to content

Commit d057d68

Browse files
committed
update post
1 parent a0cb87b commit d057d68

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

content/posts/프로젝트/당근마켓 클론코딩/당근마켓 클론코딩으로 Zod 배우기.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tags:
55
- study
66
- zod
77
createdAt: 2025-06-30 21:21:49
8-
modifiedAt: 2025-07-02 18:38:21
8+
modifiedAt: 2025-07-02 18:42:59
99
publish: 프로젝트/당근마켓 클론코딩
1010
related:
1111
- "[[당근마켓 클론코딩]]"
@@ -321,11 +321,29 @@ z.string().refine(check, message);
321321
);
322322
```
323323

324-
이런식으로 formSchema자체에 `refine`메소드를 사용할 경우 에러가 발생하면 에러 오브젝트의 `formErrors`라는 키의 리스트에 추가되어 나오게 된다.
324+
##### refine 메소드의 에러 표시
325325

326-
```json
327-
{
328-
formErrors: ["비밀번호가 일치하지 않음"]
329-
fieldErrors:{...다른 필드 에러}
330-
}
331-
```
326+
앞선 예시처럼 formSchema자체에 `refine`메소드를 사용할 경우 에러가 발생하면 에러 오브젝트의 `formErrors`라는 키의 리스트에 추가되어 나오게 된다.
327+
328+
```json
329+
{
330+
formErrors: ["비밀번호가 일치하지 않음"]
331+
fieldErrors:{...다른 필드 에러}
332+
}
333+
```
334+
335+
이때 message를 텍스트가 아닌 오브젝트로 넘겨주면서 `path`라는 키값에 특정 필드이름을 명시해 주면 해당 에러가 발생할때 해당 필드에 추가되어 결과가 나타난다
336+
337+
```typescript
338+
const formSchema = z
339+
.object({
340+
username: z.string().min(3).max(10),
341+
email: z.string().email(),
342+
password: z.string().min(10),
343+
confirmPassword: z.string().min(10),
344+
})
345+
.refine((form) => form.password == form.conformPassword, {
346+
message: "비밀번호가 일치하지 않음",
347+
path: ["confirmPassword"],
348+
});
349+
```

public/meta-data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@
579579
"tags": ["project", "carrot-market", "study", "zod"],
580580
"series": "",
581581
"createdAt": "2025-06-30 21:21:49",
582-
"modifiedAt": "2025-07-02 18:38:21",
582+
"modifiedAt": "2025-07-02 18:42:59",
583583
"publish": "프로젝트/당근마켓 클론코딩"
584584
},
585585
{

0 commit comments

Comments
 (0)