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
- Git clone
- 플러그인
- 그누보드반응형
- git lab clone
- window 정책변경
- 정적객체
- node설치
- npm install 문제
- googleicon
- fontawesome
- maxwidth
- slickslider
- 동적객체
- vscode git clone
- XEIcon
- package.json
- npm install
- 단어단위로떨어지기
- react npm install
- 글자들여쓰기
- 웹아이콘
- owlcarousel
- node 오류
- npm start
- legacy-peer
- minwidth
- 이미지반응형
- 의존성문제
- MediaQuery
- 아이콘사용법
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
타입스크립트 문법 해석 본문
728x90
📌 useState 배열 구조 분해(destructuring) 타입스크립트 문법
const [comments, setComments] = useState<{ id: string; text: string }[]>([]);
해석
✔ 구조분해
💻 [comments, setComments]
[현재 상태 값, 상태 업데이트 함수]
✔ 타입스크립트 타입 지정
💻 <{ id: string; text: string }[]>
comments는 객체 배열이며, 각 객체는 { id: string; text: string } 형태
✔ useState 초기 상태
💻 ([]);
초기 상태는 빈배열
📌 props 타입스크립트 문법
💻 export default function ClientComments({ styles } : { styles: { [key: string]: string }}) {
styles : {} => styles은 객체이다
[key: string]:string => key는 string 이고 key의 value도 string 이다
728x90
'개발 > 🔵 React-TypeScript' 카테고리의 다른 글
| Enter시 초점 이동, 함수 실행 (0) | 2025.09.17 |
|---|---|
| 전체선택 구현하기 (0) | 2025.09.16 |
| [React-TypeScript] .d.ts 파일 (0) | 2025.04.09 |
| react+typescript (0) | 2025.04.05 |
| 🔵 [React/TypeScript] 타입 좁히기, 서로소 유니온 타입 (0) | 2025.04.05 |
Comments
