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

Validating status for Promise based validations #34

Open
AleksandarDev opened this issue Mar 28, 2022 · 0 comments
Open

Validating status for Promise based validations #34

AleksandarDev opened this issue Mar 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@AleksandarDev
Copy link
Member

Use case

We have input that validates something with the server (eg. check if username already exists). It would be nice to have indicator so user known we're working on it and it's not yet confirmed.

Current state

Currently you can mimic this behaviour with following code (note the example doesn't have all features requested in this feature request, eg. 50ms delay for transitioning into validating state):

const [isUserNameValidating, setIsUserNameValidating] = useState(false);

const userName = useValidation('', validateUnique);

useEffect(() => {
    const validateUserName = () => {
        setIsUserNameValidating(true);
        await userName.validate();
        setIsUserNameValidating(false);
    };
    validateUserName();
}, [username.value]);

Please correct me if there's simpler way validating on blur

Proposal

useValidation would return one additional value validating: boolean.
The value is by default false, only changed to true when executing long running Promise validation function (eg. min. 50ms). If validation function returns in less than that - don't change state to true. Set to false immediately after validation.

Example usage:

const userName = useValidation('', validateUnique);
const isUserNameValidating = userName.validating;
@AleksandarDev AleksandarDev changed the title Loading status for Promise based validations Validating status for Promise based validations Mar 28, 2022
@AleksandarDev AleksandarDev added the enhancement New feature or request label Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant