[React + SpringBoot] 설치 및 세팅

개발자·2022년 3월 20일
0

React

목록 보기
1/2
post-thumbnail

React

이전에 사용하는 방식

  • 요청 -> View (html) -> 화면을 통째로 받는다.

  • View -> 요청(JavaScript) -> ajax(부분변경) -> 응답(JSON) -> 그림그리기(JavaScript)

이것을 발전시켜서 리액트에서는

  • React -> ajax -> 데이터변경감지 -> UI 자동 업데이트되도록
    (Observer 패턴)

따라서 React가 계속해서 동작해야하는 엔진(Daemon),서버가 필요
이것을 Node.js를 서버로 동작

React 설치

  • VS code 설치

  • Node.js 설치 (npm 명령어 사용가능)

  • 터미널에서 npx create-react-app my-app 명령어를 통해 설치가능

  • my-app 폴더에서 npm start 명령어를 통해 실행

  • VS code 편리한 기능 설치

  1. ESLint
  2. Prettier => 코드정렬
  3. Reactjs code snippets => 리액트 코드 자동완성

React 실행흐름

  • React는 SPA(Single Page Application) 이다. (a태그 사용불가)

index.js

ReactDOM.render(
    <App />,
  document.getElementById('root')
);

index.js 를 확인해보면 다음과 같은 코드를 확인 할 수 있다.

App.js

import logo from './logo.svg';
import './App.css';

function App() {
  return <div>안녕1</div>; 
}

export default App;

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

다음과 같이 되어있는데 즉
div id="root" 라고 되어있는곳에 app에 적힌것을 띄운다는 의미이다.
그것을 리액트가 렌더링하는것.

React jsx문법

  • HTML과 유사한 구조를 가지고 있어 직관적이고 사용하기 유용한 문법

  • 자바스크립트에 HTML 문법을 사용하는것.
    다음과 같이.

function App() {
  return <div>안녕1</div>; 
}

0개의 댓글