react component function2 Component 2, 파일 분리 (모듈화) Component 1, function 컴포넌트() Q. 아래 코드 중 .diary 영역을 function()을 이용하여, 컴포넌트화 해보자. import './App.scss'; function App() { let title = 'Blog'; function thisYear(){ let now = new Date(); return now.getFullYear();.. fresh-mint.tistory.com 위 글에서 컴포넌트 를 새파일로 분리 해보자. 1. 파일 생성, 컴포넌트.js 일반적으로 파일명은 컴포넌트명과 동일하게 주어지고, 역시 동일하게 첫문자는 대문자로 작성한다(Diary.js). 2. function Diary(){} 를 삽입하고 리액트 기본 설정 값을 추가 import React f.. 2021. 10. 29. Component 1, function 컴포넌트() Q. 아래 코드 중 .diary 영역을 function()을 이용하여, 컴포넌트화 해보자. import './App.scss'; function App() { let title = 'Blog'; function thisYear(){ let now = new Date(); return now.getFullYear(); } return ( { title } { thisYear() } 제목 날짜 상세내용 ); } export default App; A. 컴포넌트 function의 첫 문자는 대문자! 1. 먼저 function()을 생성하여, 처럼 함수에 컴포넌트를 담는다. 이전글에서 설명했듯이, return() 바로 안에는 한 개 이상의 태그가 들어갈 수 없다. 전체를 감싸는 태그, 하나만 삽입되어야 한다(역.. 2021. 10. 29. 이전 1 다음