jotaijs / jotai-form

Form atoms for Jotai
MIT License
135 stars 1 forks source link

Typing error using jotai 1.12.1 #13

Closed devnomic closed 1 year ago

devnomic commented 1 year ago

I wanted to try this lib with latest jotai lib however it produce typing error.

Screen Shot 2023-01-15 at 20 33 11

I literally followed the example in the readme.

// defining a validation schema for the atom
const emailSchema = Yup.string().email().required();

// creating the atom with an async validation function
const emailAtom = atomWithValidate('', {
  validate: async (v) => {
    await emailSchema.validate(v);
    return v;
  },
});

export default function SomeComponent() {
  const [email, setEmail] = useAtom(emailAtom); // error here
}
dai-shi commented 1 year ago

Sorry for the inconvenience. v0.1.0 is already migrated Jotai v2 API (because we can use the prerelease in jotai v1). In your case, please use v0.0.4 until jotai v2 is released.

npm install jotai-form@0.0.4
devnomic commented 1 year ago

I see thank you, however it produce another typing error when checking isValid like in the example.

Screen Shot 2023-01-15 at 22 04 39
dai-shi commented 1 year ago

Can you create a minimal reproduction with https://codesandbox.io/s/react-typescript-react-ts ?

devnomic commented 1 year ago

Here it is: https://codesandbox.io/s/ecstatic-paper-op43j5?file=/src/App.tsx

Sorry for long time. I really like jotai, i think it's the best!

dai-shi commented 1 year ago

Thanks. Because it's an async validation, it can be in progress. You need to check isValidating property. https://codesandbox.io/s/charming-moon-1vycuk

devnomic commented 1 year ago

I see, thank you @dai-shi. It seems the readme basic example needs update then, since i just copy pasted the code from the readme.

dai-shi commented 1 year ago

Good point.

Would you be willing to open a PR?

Confirmed that examples/02 seems correct: https://github.com/jotai-labs/jotai-form/blob/b52543d8ffedc17ebbb219d854a5aa1f247b8f95/examples/02_typescript/src/App.tsx#L29-L31