Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- bucket list
- JavaScript
- nomadcoders
- 객체지향
- 리액트
- ENFJ포스팅
- 이메일 코딩
- 국비지원
- class
- 바이트디그리
- redux
- REACT강의
- K디지털기초역량훈련
- 버킷리스트
- 자바스크립트
- React & Redux로 시작하는 웹 프로그래밍
- object-oriented programming
- CSS
- 내일배움카드
- HTML
- 코딩
- 반응형 이메일
- free react course
- ENFJ
- 반응형
- 무료리액트강의
- 노마드코더
- 패스트캠퍼스
- react
Archives
- Today
- Total
미미 공부/취미방
[노마드 코더] Creating your first React Component #2.0 본문
1) This site can't be reached는 서버가 동작되고 있지 않아서 생긴다.
Terminal에 npm start 입력해서 서버를 시작하면
작업중인 페이지가 브라우저에 나타난다.
Local: http://localhost:3000
//작업중인 컴퓨터 브라우저에서 사용
On Your Network: http://192.168.219.105:3000
//같은 와이파이 연결된 기기에서 사용
3) JSX는 JavaScript와 HTML의 결합
ex) <App />
React.js는 바닐라 자바스크립트와 동일한 콘셉트로 동작하지만 JSX는 React에서만 사용된다.
4) Component를 만들어 보자
src폴더에 새 파일을 만든다. ex) Potato.js
새 파일에는 반.드.시.
import React from "react";
를 넣어줘야됨
5) 어디에, 어떻게 Potato.js를 넣어야될까?
index.js에는 딱 1개의 component만 render 되어야하기 때문에 아래 코드는 동작하지 않는다.
(component 를 2개 render 하기 때문에)
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import Potato from "./Potato";
ReactDOM.render(<App /><Potato />, document.getElementById("root"));
//혹은
ReactDOM.render(<App />, document.getElementById("root"));
ReactDOM.render(<Potato />, document.getElementById("root"));
그러므로,
App.js안에서 Potato를 import하고 HTML로 넣어준다.
import React from "react";
import Potato from "./Potato";
function App() {
return (
<div>
<h1>Hello</h1>
<Potato />
</div>
)
}
export default App;
**React는 단 1개의 Component만 render할 수 있음
**모든 Component는 App Component 안에 있어야 됨.
6) Index.html / index.js / App.js
Public 폴더에 있는 index.html이 브라우저에 로드되고
function들로 만들어진 요소들이 그 안에 뿌려지게 된다.
**React 동작이 빠른 이유
//index.html
<div id="root"></div>
+
//App.js
import React from "react";
function App() {
return(
<div>
<h1>Hello</h1>
</div>
)
}
+
//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById("root"));
결과
<div id="root">
<h1>Hello</h1>
</div>
'to FED' 카테고리의 다른 글
[노마드 코더] Protection with PropTypes #2.4 (0) | 2021.10.16 |
---|---|
[노마드 코더] Reusable Components with JSX + Props #2.1 (0) | 2021.10.16 |
[git] 보여지는 경로명과 복사한 경로명이 다름 / 경로명에 띄어쓰기가 있음 (0) | 2021.09.09 |
동기 비동기 (0) | 2021.09.05 |
"실전 리액트 프로그래밍"으로 스터디 시작 (0) | 2021.09.03 |
Comments