useCheckUsernameAvailability
Overview
The useCheckUsernameAvailability
hook is used to check if a specified username is available for use in the current project. This is helpful during user registration or profile updates to ensure the uniqueness of usernames.
Usage Example
import { useCheckUsernameAvailability } from "@replyke/react-js";
function UsernameCheck({ username }: { username: string }) {
const checkUsernameAvailability = useCheckUsernameAvailability();
const handleCheckAvailability = async () => {
try {
const isAvailable = await checkUsernameAvailability({ username });
console.log(
isAvailable ? "Username is available." : "Username is already taken."
);
} catch (error) {
console.error("Failed to check username availability:", error.message);
}
};
return <button onClick={handleCheckAvailability}>Check Availability</button>;
}
Parameters & Returns
Parameters
The hook returns a function that accepts an object with the following field:
Parameter | Type | Required | Description |
---|---|---|---|
username | string | Yes | The username to check for availability. |
Returns
The function resolves with a boolean value:
Return Value | Type | Description |
---|---|---|
isAvailable | boolean | true if the username is available, otherwise false . |