티스토리 뷰

React

[React] 실습 / 리스트 조회(rendering)

에스파니아 2022. 4. 18. 21:19
728x90
반응형

개요



부모 태그에서 전달받은 데이터를 리스트 형태로 출력 해보자.

 

 

App.js(부모 태그)



import "./App.css";
import ReportList from "./ReportList";

const App = () => {
  const dummyList = [
    {
      id: 1,
      author: "espania",
      content: "하이",
      grade: 1
    },
    {
      id: 2,
      author: "권영욱",
      content: "하이2",
      grade: 2
    },
    {
      id: 3,
      author: "권기웅",
      content: "하이3",
      grade: 3
    }
  ];
  return (
    <div className="App">
      <ReportList reportList={dummyList} />
    </div>
  );
};
export default App;

 

dummyList 배열 변수를 ReportList Component에 전달한다.

 

 

ReportList(자식 태그)



const ReportList = ({ reportList }) => {
  return (
    <div>
      <h2>보고 리스트</h2>
      <div>
        {reportList.map((it) => {
          return (
            <div key={it.id}>
              <div>
                <span>작성자 : {it.author}</span>
              </div>
              <div>
                <span>내용 : {it.content}</span>
              </div>
              <div>
                <span>보고 : {it.grade}</span>
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
};

export default ReportList;​

 

배열의 map 함수를 활용하여 dummyList 배열을 리스트 형태로 출력 할 수 있다.



참고



https://espania.tistory.com/354
 

[React] 실습 / 사용자 입력 처리

한 줄 입력 처리 React 에서 state를 활용하여 input 태그의 value 값을 초기화 해주거나 변경 해 줄 수 있다. import { useState } from "react"; const ReportEditor = () => { const [author, setAuthor] = use..

espania.tistory.com

https://espania.tistory.com/355

 

[React] 실습 / DOM 조작 / useRef

개요 저장 버튼 클릭 했을 때, HTML 태그들의 유효성 검사(정상적으로 입력이 되었는지 확인) 하고 아니라면 해당 태그를 focus 하도록 한다. 작성자 input 태그는 최소 1글자 이상 입력해야하고, 보

espania.tistory.com


https://codesandbox.io/s/icy-rain-hidu02?file=/src/App.js 

 

icy-rain-hidu02 - CodeSandbox

icy-rain-hidu02 by jins4731 using react, react-dom, react-scripts

codesandbox.io


728x90
댓글
반응형
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/01   »
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
글 보관함