React - Start - 01
About React and Setting
What is React and purpose?
- Javascript library
- show content(HTML) to users and handle user interaction
What was the HTML looking stuff?
- JSX
- It looks like HTML
- Can be placed in JavaScript code
Why did we add to libraries(React and ReactDOM)?
- React is split into two separate libraries
- ‘React’ knows what a component is and how to make components work together
- ‘ReactDOM’ knows ho to take a component and make it show up in the DOM
Generate React project
- Install/Update Node.js
- Install create-react-app(
npm install -g create-react-appnpx create-react-app {name of project}) - Generate a project
- Build project
Babel
브라우저가 지원하는 JavaScript 버전으로 원래의 JavaScript 파일을 변환해주는 라이브러리Structor in React Project
- src: 작성한 소스 코드 저장 폴더
- public: 이미지와 같은 static한 파일 저장 폴더
- node_modules: dependencies
- package.json: dependencies를 기록 및 구성
- package.lock.json: 프로젝트에 필요한 패키지의 정확한 버전 기록
- README.md: 프로젝트 사용법
Control+CStart the app up in the future:
npm startAccess: localhost:3000
React Process in index.js
-
Import the React and ReactDOM libraries
import React from 'react'; import ReactDOM from 'react-dom'; -
Create a react component
const App = () => { return <div>Hi there!</div> }; -
Take the react component and show it on the screen
ReactDOM.render( <App />, // index.html의 body부분의 id 참고 document.querySelector('#root') );
import and require
import: ES2015 Modules(ES2015 import statement)required: CommonJS Modules(CommonJS import statement)
댓글
댓글 쓰기