목록2024/08 (47)
wintertreey 님의 블로그
핵심로직 먼저 후다닥 작성하자. AritcleInter.javapackage pack;public interface ArticleInter { void selectAll();}ArticleDao.javapackage pack;public class ArticleDao implements ArticleInter { @Override public void selectAll() { System.out.println("테이블 자료 읽기"); }} LogicInter.javapackage pack;public interface LogicInter { void selectDataProcess1(); void selectDataProcess2();} LogicImpl.javapackage pack;public cl..
"" (문자열 리터럴)과 {} (중괄호) input type="text" value="0" readOnly>input> 문자열 리터럴 "": value="0"은 입력 필드의 값을 "0"으로 설정.값이 하드코딩됨: 이 경우, value 속성은 항상 문자열 "0"을 가진다. React 상태나 props에 의존하지 않으며, 이 값은 고정되어 있다.만약 value={}로 적는다면중괄호 {}: {}를 사용하면 JavaScript 표현식을 JSX 내에서 평가하게된다. 예를들어 value={this.props.number}는 this.props.number라는 JavaScript 표현식을 평가하여 value 속성에 설정해준다.동적 값: value 속성에 설정된 값이 컴포넌트의 상태나 props에 따라 동적으로 변할..
import React from "react";class Clock2 extends React.Component{ constructor(props){ super(props) this.state = {date:new Date()} //state를 생성자에서 지정 } //Mount: DOM 객체가 생성되고 브라우저에 나타나는 것 //호출순서: constructor> getDerivedStateFromProps> render> componentDidMount showSigan(){ this.setState({ date:new Date() }) } componentDidMount(){ //시스템에 의한 ..
이번 기회에 부트스트랩을 도입해보려고 한다. 리액트에서는 쉽게 부트스트랩 css 파일을 통한 적용이 가능하다. 1. 부트스트랩 설치터미널에 다음 명령어를 사용하여 부트스트랩을 설치한다. npm install bootstrap 2. 부트스트랩 CSS 파일을 importsrc/index.js 또는 src/App.js 파일에 다음을 추가하여 부트스트랩 CSS 파일을 import한다.이때 다른 파일에는 굳이 import 를 해주지 않아도 된다. import 'bootstrap/dist/css/bootstrap.min.css'; 3. 그다음 부트스트랩 사이트를 참고하여 각 태그의 className에 소스를 추가해주면된다. 라우터 연습을 하면서 확인해보자. App.jsimport React from "rea..
라우터란?사용자가 요청한 URL에 따라 해당 URL에 맞는 페이지를 보여주는 것이라고 생각하면 된다. 리액트에서는 라우팅 관련 라이브러리가 많은데, 이중 가장 많이 쓰이는 React Router 활용. 리액트는SPA (Single Page Application) 방식 - 기존 웹 페이지 처럼(MPA 방식) 여러 개의 페이지를 사용, 새 페이지를 로드하는 방식이 아니다. - 새 페이지를 로드 하지 않고 하나의 페이지 안에서 필요한 데이터만 가져오는 형태를 가진다.React-Router는 신규 페이지를 불러오지 않는 상황에서 각각의 url에 따라 선택된 데이터를 하나의 페이지에서 렌더링 해주는 라이브러리라고 할 수 있다. 라우터를 사용하기 전에 설치해줘야한다. 터미널에서 다음과 같이 명령문을 적어주자. np..
텍스트에 값 입력하여 투두리스트를 띄워보자. 간단한 설명은 코드 옆에 주석으로 달아두었다. import React, {useState} from "react";function TodoList({items}){ //할일목록 출력용 return( {items.map((item) => ( // items 배열을 순회하며 각 항목을 리스트 요소로 렌더링 {item.text} ))} );}function App() { const [items, setItems] = useState([]);// 할 일 목록을 관리하는 상태 const [text, setText] = useState('');// 입력 필드의 현재 값을 관리하는 상태 const handl..
React.memo() React는 먼저 컴퍼넌트를 렌더링(rendering) 한 뒤, 이전 렌더된 결과와 비교하여 DOM 업데이트를 결정한다. 만약 렌더 결과가 이전과 다르다면, React는 DOM을 업데이트한다. 컴퍼넌트가 React.memo()로 래핑 될 때, React는 컴퍼넌트를 렌더링하고 결과를 메모이징(Memoizing)한다. 그리고 다음 렌더링이 일어날 때 props가 같다면, React는 메모이징(Memoizing)된 내용을 재사용한다. 메모이징 한 결과를 재사용 함으로써, React에서 리렌더링을 할 때 가상 DOM에서 달라진 부분을 확인하지 않아 성능상의 이점을 누릴 수 있다. 언제 React.memo()를 써야할까같은 props로 렌더링이 자주 일어나는 컴퍼넌트.React.memo(..