Skip to content
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

docs: add valibot example #21

Merged
merged 4 commits into from
Dec 4, 2023
Merged

Conversation

Odonno
Copy link
Contributor

@Odonno Odonno commented Nov 25, 2023

Add valibot example by taking inspiration from the Zod example.

At first, I mimic the Zod example using the parse function but I made the change to use the safeParse. It feels like the lib misses a safeValidate/safeValidateAsync function alternative. Here is how it could look like to have an API fully compatible with safeParse:

const emailAtom = atomWithValidate('demo@jotai.org', {
  safeValidate: (email, { onSuccess, onError }) => {
    const result = safeParse(emailSchema, email);
    return result.success ? onSuccess(email) : onError(result.issues);
  },
});

Copy link

codesandbox-ci bot commented Nov 25, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9f7cbf0:

Sandbox Source
React Configuration
React TypeScript Configuration

@barelyhuman
Copy link
Collaborator

Hey,

Thanks for the addition of the example!

It feels like the lib misses a safeValidate/safeValidateAsync function alternative. Here is how it could look like to have an API fully compatible with safeParse

The function itself should be trivial to add, most work will be to make sure the propagation to the other wrappers jotai-form provides.

I'll see if I can pick this up 😄 , thanks for suggestion and the API example

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

not familiar with valibot, but adding examples would be nice.

@barelyhuman barelyhuman merged commit e7f7fad into jotaijs:main Dec 4, 2023
2 checks passed
@Odonno Odonno deleted the feat/valibot-example branch December 4, 2023 09:55
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.

None yet

3 participants