chore(shared): Update signature of useReverification for error handling configuration - #4564
Conversation
🦋 Changeset detectedLatest commit: 43ee306 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
useReverification for error handling configurationuseReverification for error handling configuration
…should-not-throw-on-cancel-by-default
…should-not-throw-on-cancel-by-default
…should-not-throw-on-cancel-by-default # Conflicts: # packages/shared/src/react/hooks/useReverification.ts
This allows for new references to be used, when something else is causing the re-render
panteliselef
left a comment
There was a problem hiding this comment.
For reviewers, do you think this is acceptable ?
const [createEmailAddress] = useReverification(() => user?.createEmailAddress({ email: emailField.value }));
...
const onSubmit = async () => {
await createEmailAddress()
}or we should force this ?
const [updatePasswordWithReverification] = useReverification(
(user: UserResource, opts: Parameters<UserResource['updatePassword']>) => user.updatePassword(...opts),
);
...
const onSubmit = async () => {
try {
const opts = {
newPassword: passwordField.value,
signOutOfOtherSessions: sessionsField.checked,
currentPassword: user.passwordEnabled ? currentPasswordField.value : undefined,
} satisfies Parameters<typeof user.updatePassword>[0];
await updatePasswordWithReverification(user, [opts]);
onSuccess();
} catch (e) {
handleError(e);
}
};| })(fetcherRef.current); | ||
| return [handler] as const; | ||
| }, [__experimental_openUserVerification, fetcherRef.current]); | ||
| }, [__experimental_openUserVerification, fetcherRef.current, optionsRef.current]); |
There was a problem hiding this comment.
Adding the references in here, will not cause the useMemo to re-render explicitly, but if something else causes the Component that the hook is mounted on, this will use the new references if they changed
| * } | ||
| */ | ||
| function __experimental_useReverification< | ||
| Fetcher extends (...args: any[]) => Promise<any> | undefined, |
There was a problem hiding this comment.
I've added undefined here, in order to support the following
const {user} = useUser()
const [update] = useReverification(()=>user?.update({userName})|
|
||
| async function resolveResult<T>( | ||
| result: Promise<T>, | ||
| result: Promise<T> | T, |
There was a problem hiding this comment.
Accept the value itself, e.g. undefined instead of Promise<undefined>
…should-not-throw-on-cancel-by-default
…ling configuration (#4564)
Description
Given this server action
when it is used as
but if you use it like with
throwOnCancel: truethennullwill not never be returned since we throw.Checklist
npm testruns as expected.npm run buildruns as expected.Type of change