반응형
모달창
-
컴포넌트 생성, 사용하기프레임워크/리액트 React 2023. 1. 16. 18:23
컴포넌트 html은 사용이 많아지기 때문에 코드가 더러워지는 단점이 있다. 리액트에서는 이 부분을 해결하기 위해 컴포넌트를 만들어 사용한다. 뿐만 아니라 해당 컴포넌트를 보면, 어떤 기능을 하는지 명확히 알 수 있는 장점도 있다. → 가독성이 좋아지고, 코드의 재활용에 좋다. 1. 컴포넌트(component) 생성 function을 만들고, return() 안에 html 담기 쓰기 또는 1) 주의사항 다른 function 바깥쪽에 작성할 것 function 이름은 영문 대문자로 시작 (ex: Modal) return() 안에는 하나의 태그로 시작해 하나의 태그로 끝나야 함 → 여러개의 태그를 사용하고 싶을 때는 가장 바깥쪽에 로 감싸준다(fragment 문법) → 참고사이트 : https://ko.rea..