The useSignUp hook provides a simplified interface for managing the multi-step Clerk sign-up process in an Expo application. It abstracts the complexity of calling Clerk's underlying methods for password creation, email verification, and session finalization.
It provides three main capabilities:
signUp: Initiates the sign-up process with an email and password, and automatically triggers the email verification code delivery.verifyOtp: Verifies the email code (OTP) provided by the user and, if the status is complete, finalizes the sign-up and navigates the user to the root (/) using expo-router.isLoaded: A boolean indicating if the Clerk sign-up state is ready to be used (i.e., fetchStatus is idle).
Note: This hook uses expo-router for navigation upon successful finalization.
import { useSignUp } from './path-to-your-hooks/useSignUp';
const SignUpScreen = () => {
const { isLoaded, signUp, verifyOtp } = useSignUp();
const handleSignUp = async () => {
try {
await signUp({ email: 'user@example.com', password: 'securePassword123' });
// Proceed to OTP input screen
} catch (err) {
console.error('Sign up failed:', err);
}
};
const handleVerify = async (token: string) => {
try {
await verifyOtp({ token });
} catch (err) {
console.error('Verification failed:', err);
}
};
if (!isLoaded) return <LoadingView />;
return (
// Your UI components
);
};