Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 285af78

Browse files
Whole Input Validation Added
1 parent b76201f commit 285af78

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ function App() {
9292
</Stack>
9393
</Stack>
9494
<Button
95+
type='submit'
9596
variant='contained'
97+
disabled={!password.isInputValid}
9698
sx={{
9799
p: '.8em 2em',
98100
textTransform: 'none',

‎src/hooks/useValidation.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React,{ useState, useEffect } from 'react';
1+
import { useState, useEffect } from 'react';
22

33
export const useValidation = (value: string, validations: any[]) => {
44
const [isEmpty, setIsEmpty] = useState(true);
5-
const [isEmailError, setIsEmailError] = useState(true);
5+
const [isEmailError, setIsEmailError] = useState(false);
66
const [isMinLengthError, setIsMinLengthError] = useState(false);
77
const [isMaxLengthError, setIsMaxLengthError] = useState(false);
8+
const [isInputValid, setIsInputValid] = useState(false);
89

910
useEffect(() => {
1011
for (const validation in validations) {
@@ -33,10 +34,19 @@ export const useValidation = (value: string, validations: any[]) => {
3334
}
3435
}, [value]);
3536

37+
useEffect(() => {
38+
if (isEmpty || isMinLengthError || isMaxLengthError || isEmailError) {
39+
setIsInputValid(false);
40+
} else {
41+
setIsInputValid(true);
42+
}
43+
}, [isEmpty, isMinLengthError, isMaxLengthError, isEmailError]);
44+
3645
return {
3746
isEmpty,
3847
isMinLengthError,
3948
isMaxLengthError,
4049
isEmailError,
50+
isInputValid,
4151
};
4252
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /