Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- vscode git clone
- npm start
- 의존성문제
- 웹아이콘
- 글자들여쓰기
- Git clone
- owlcarousel
- 그누보드반응형
- 이미지반응형
- 단어단위로떨어지기
- maxwidth
- minwidth
- 아이콘사용법
- legacy-peer
- npm install 문제
- package.json
- googleicon
- 플러그인
- node 오류
- npm install
- slickslider
- MediaQuery
- XEIcon
- 동적객체
- react npm install
- node설치
- window 정책변경
- 정적객체
- git lab clone
- fontawesome
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
Enter시 초점 이동, 함수 실행 본문
728x90
CRUD란?
C 새로운 데이터 생성R 데이터 조회U 기존 데이터 수정D 데이터 삭제 C = Creat = POST R = Read = GET U = Update = PUT(전체 데이터 교체) / UPDATE(일부만 수정) D = Delete = DELETE 예시)POST /posts → 게시글 작성GET /p
dazzle-bini.tistory.com
👆이전 코드를 사용하여 코드 보완
+ 추가할 때 엔터시 가능, 이름 필드에서 엔터시 생일 필드로 초점 이동
import { useRef } from "react";
// 포커스 이동
const nameRef = useRef<HTMLInputElement>(null);
const birthRef = useRef<HTMLInputElement>(null);
<label htmlFor="inpName">이름</label>
<input
type="text"
id="inpName"
placeholder="이름을 입력하세요"
ref={nameRef}
value={newName}
onChange={e => setNewName(e.target.value)}
onKeyDown={e => {
if(e.key === "Enter") birthRef.current?.focus();
}}
/>
<br />
<label htmlFor="inpBirth">생일</label>
<input
type="text"
id="inpBirth"
placeholder="ex) 2000.01.01"
ref={birthRef}
value={newBirth}
onChange={e => setNewBirth(e.target.value)}
onKeyDown={e => {
if(e.key === "Enter") addUser(); // 엔터시 추가 함수 호출
}}
/>
💻 input에 ref 속성과 onKeyDown 속성 추가
const birthRef = useRef(null); 라고 써도 되지만 타입스크립트이기 때문에
const birthRef = useRef<HTMLInputElement>(null); 타입을 써준다.
728x90
'개발 > 🔵 React-TypeScript' 카테고리의 다른 글
| 버튼 컴포넌트 1차 (0) | 2025.09.18 |
|---|---|
| 오류 검증 (0) | 2025.09.17 |
| 전체선택 구현하기 (0) | 2025.09.16 |
| 타입스크립트 문법 해석 (1) | 2025.08.27 |
| [React-TypeScript] .d.ts 파일 (0) | 2025.04.09 |
Comments
