웹 링크 유효성 검사
let regex = /^(http(s)?:\/\/)([^\/]*)(\.)(com|net|kr|my|shop)/gi;
const trueOrFalse = regex.test(input);
if (trueOrFalse === true) {
setErrorMessage('');
setInputValidation(true);
} else {
setErrorMessage('유효한 주소를 적어주세요.');
setInputValidation(false);
}
/: 정규식 시작
^: 문자열의 시작
(http(s)?:\/\/): http:// 또는 https:// 허용
([^\/]*): ^는 not의 의미로 /를 제외한 모든 문자열을 허용한다.
(\.): .를 선언해야 한다.
(com|net|kr|my|shop): 선언된 것만 허용한다.
/: 정규식 끝
g: 전역
i: 대소문자 구분 없음
React Query Firebase
React Query Firebase 쓰기 전
// github 수정
const docRef = doc(db, 'users', currentUser.uid);
const mutation = useFirestoreDocumentMutation(docRef);
const useSaveEdit = () => {
const docRef = doc(db, 'users', currentUser.uid);
if (docRef.converter === null) {
await setDoc(docRef, {
github: currentInput,
});
updateGithub(currentInput);
} else {
await updateDoc(docRef, {
github: currentInput,
});
updateGithub(currentInput);
}
}
React Query Firebase 쓴 후
import { useFirestoreDocumentMutation } from '@react-query-firebase/firestore';
const docRef = doc(db, 'users', currentUser.uid);
const mutation = useFirestoreDocumentMutation(docRef);
const useSaveEdit = () => {
mutation.mutate({ github: currentInput });
updateGithub(currentInput);
}
'개발 일지 > TIL' 카테고리의 다른 글
[ KTP ] CSS 프로젝트 회고 (0) | 2023.01.30 |
---|---|
[ TypeScript ] (0) | 2023.01.27 |
[ React ] 하나의 modal로 버튼에 따라 다른 내용 출력하기 (0) | 2023.01.24 |
[ TypeScript ] TypeScript 설치 및 파일 생성 (0) | 2023.01.21 |
[ React Query ] 게시물에 따른 comments 업데이트 (0) | 2023.01.21 |
댓글