Skip to content

Fix: Avoid implicit type coercion in validation logic examples #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 15, 2025

Conversation

minseong0324
Copy link
Contributor

@minseong0324 minseong0324 commented Jan 14, 2025

  • Replaced implicit type coercion (!value) in the validation logic with an explicit comparison using value.trim() === "".
  • Ensures that input containing only whitespace is also treated as invalid.

ref: #21

Copy link

vercel bot commented Jan 14, 2025

@minseong0324 is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@@ -38,7 +38,8 @@ export function Form() {
<div>
<input
{...register("name", {
validate: (value) => (!value ? "이름을 입력해주세요." : ""),
validate: (value) =>
(value.trim() === "" ? "이름을 입력해주세요." : ""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good if "Please enter your name." is displayed even when the value is nullish.
How about handling this with a utility function like isEmptyStringOrNil(value)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

663c6a9

Thanks for your good comment. I applied isEmptyStringOrNil function to verify nullish value.

@minseong0324 minseong0324 force-pushed the chore/implicit-coercion branch 2 times, most recently from 6230fcb to 2559593 Compare January 15, 2025 11:58
@minseong0324 minseong0324 force-pushed the chore/implicit-coercion branch from 2559593 to 663c6a9 Compare January 15, 2025 12:00
@minseong0324 minseong0324 requested a review from Kimbangg January 15, 2025 12:05
Copy link
Member

@Kimbangg Kimbangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minseong0324 Thank you for accepting the feedback. LGTM 🚀

@Kimbangg Kimbangg merged commit c0476d9 into toss:main Jan 15, 2025
1 check failed
@minseong0324 minseong0324 deleted the chore/implicit-coercion branch January 15, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants