# React-16.3. 이벤트에서 state 변경하기

이벤트 내에서 컴포넌트의 정보를 바인딩 하여 사용 할 때, 직접 변경할 수 없고, 함수형태로 변경해야 한다.

1. App으로 옮겨온 subject의 title 클릭시  mode로 정의한 state를 read로 변경

1.1 오류발생 코드

 - 이벤트가 호출된 상태의 this는 이벤트의 상태를 참조한다. (컴포넌트에 설정된 state를 사용할 수 없음

: src\App.js - render 로 옮겨온 subject 코드의 이벤트 수정
onClick={function(e){
  console.log(e);
  e.preventDefault();
  this.state.mode = 'welcome';
}}

1.2 이벤트에 컴포넌트의 this를 전달

 - 오류는 발생하지 않지만, 동작하지 않음 (mode 정보 설정)

onClick={function(e){
  console.log(e);
  e.preventDefault();
  this.state.mode = 'welcome';
}.bind(this)}

1.3 이벤트에서 컴포넌트의 값을 사용할 수 있도록 this 정보 설정

 - 설정 후 개발자도구에서 mode 값을 'read'로 변경하면 본문이 바뀜(컴포넌트의 state 값 변경으로 새로고침 됨)

 > 이후 subject의 title 클릭시 mode 값이 welcome 으로 변경되면서 본문 바뀜 (Hello, React !!)

onClick={function(e){
  console.log(e);
  e.preventDefault();
  // this.state.mode = 'welcome'; 동작하지 않음
  this.setState({
    mode:'welcome'
  });
}.bind(this)}

# React-16.2. 이벤트 설치

 

* subject와 toc의 title 클릭시 app의 state를 통해 article 영역(본문)에 해당 컨텐츠를 표시

1. subject 의내용을 풀어서 app에 적용

: src\components\Subject.js - render()의 return 코드
<header>
  <h1><a href="/">{this.props.title}</a></h1>
  {this.props.sub}
</header>

: src\App.js return의 아래 내용을 대체
<Subject 
  title={this.state.subject.title} 
  sub={this.state.subject.sub}>
</Subject>

: src\App.js return에 적용한 코드
<header>
  <h1><a href="/">{this.state.subject.title}</a></h1>
  {this.state.subject.sub}
</header>

2. 이벤트 적용

: 1차 적용 이벤트 - 실행 후 화면이 다시 로딩된다.
onClick={function(){
  alert('hi');
}}

: 2차 적용 이벤트 - 디버그로 로그 표시 (콘솔에서 e.preventDefault(); 로 새로고침 제한 테스트)
onClick={function(e){
  console.log(e);
  debugger;
}}

: 3차 적용 이벤트 - 화면 새로고침 방지 이벤트 적용
onClick={function(e){
  console.log(e);
  e.preventDefault();
}}

 - subject title을 클릭하면 e.preventDefault로 인해 새로고침이 되지 않음

# React-16.1. 이벤트 state props 그리고 render 함수

 - event

 - 애플리케이션의 역동성 구성 : event, props, state 의 상호작용

1. title : WEB 에 링크추가

 - 클릭시 본문(Content)에 Welcom 메시지 표시

:src\components\Subject.js
<h1><a href="/">{this.props.title}</a></h1>

2. toc 항목 클릭시 본문에 해당 내용 표시

3. 각 링크마다 이벤트 설치(다음시간)

 - App 컴포넌트의 state 값에 따라 content의 컴포넌트의 props를 변경하고

   변경사항이 컴포넌트에 반영이 되도록 개선

3.1 state 셋팅

 - mode 속성 추가 : 기본값 - welcom

 - 상태별 state 속성 추가 : welcom

 > react 에서는 state, propse 값이 변경되면 render 함수가 다시 호출되어 화면을 그리게 됨(하위컴포넌트 포함)

    render : 어떤 html을 그릴지 결정하는 역할

3.2 state 변경 (크롬 개발자도구 - React Developer Tools)

 - 개발자도구 Components 텝에서 App의 속성 확인 : Props, State

 > 확인 - State > mode : "welcome" 

 > 수정 - State > mode : "read" 

 

* consele을 표시하여 state, propse 변경시 마다 render가 호출되는것을 확인

:src\App.js render()
console.log("App render");

:src\components\Subject.js render()
console.log("Subject render");

:src\components\TOC.js render()
console.log("TOC render");

:src\components\Article.js render()
console.log("Article render");

 

* 개발자 도구(React Developer Tools)에서 변경한 속성(Props.mode)에 따라

  각 컴포넌트들(App, Subject, Toc, Article)이 다시 그려지며(render) 메시지가 변경한 것을 확인

# React-15.1. State 소개

 - state, props

 - 사용자가 조작하는 부분 (props) : 유저 인터페이스(버튼, 터치스크린 등)

 - 구현자가 조작하는 부분 (state) : 상태

 - 컴포넌트 사용 : props (사용자가 조작하는 속성), state (컴포넌트가 내부적으로 관리하는 정보)

 > state를 알아보며 props도 이해하자

 

# React-15.2. State 사용

 - App > Subject : props 하드코딩 > state로 전환하여 개선하자

<!-- 하드코딩된 props 값 : "WEB2","React JSX." -->
<Subject title="WEB2" sub="React JSX."></Subject>

 - 생성자(constructor)를 이용해 state 값을 정의하고 초기화한다.

 > 컴포넌트가 실행될때 render()를 실행하기 전에 constructor를 실행하여 컴포넌트 초기화를 담당함

constructor(props){
  super(props);
  this.state = {
    subject : {title:"WEB", sub:"World Wid Web!"}
  }
}

 - 생성자에서 정의한 state를 이용하여 Subject 컴포넌트의 props 정보를 정의한다.

<Subject 
  title={this.state.subject.title} 
  sub={this.state.subject.sub}>
</Subject>

 - App을 호출하는 index에서는 App의 state정보를 알지 못한다.(알 필요가 없고, 알아서도 안된다.)

 - 상위컴포넌트(App)에서 정의한 state 값은 하위컴포넌트(Subject)에서 사용(전달)할 수 있다.

 

# React- 15.3. key

 - TOC 의 내용을 App의 state를 이용하여 변경할 수 있도록 개선

 - App의 생성자에서 TOC에 전달할 속성 정의

this.state = {
  subject : {title:"WEB0", sub:"World Wid Web!!"},
  contents:[
    {id:1, title:'HTML', desc:'HTML is for information'},
    {id:2, title:'CSS', desc:'CSS is for design'},
    {id:3, title:'JavaScript', desc:'JavaScript is for interactive'}
  ]
}

 - TOC에서 전달받은 속성정보를 이용하여 내용을 표시할 수 있도록 수정

<Toc data={this.state.contents}></Toc>

 - TOC의 render 함수를 수정하여 App에 설정된 state에 따라 표시되도록 수정

 > App에 설정된 contents의 항목을 지우면 Toc의 render로 생성되는 항목도 함께 삭제됨

render(){
  var lists = [];
  var data = this.props.data;
  var i = 0;
  while(i < data.length){
    lists.push(<li><a href={"/content/"+data[i].id}>{data[i].title}</a></li>);
    i = i + 1;
  }
  return(
    <nav>
      <ul>
        {lists}
      </ul>
  </nav>
  );
}

 > 오류발생 : react에서 스크립트로 생성하는 화면요소는 식별정보(key)를 표시해야 함.

lists.push(<li key={data[i].id}><a href={"/content/"+data[i].id}>{data[i].title}</a></li>);

* react에서 여러 엘리먼트를 자동으로 생성하도록 작업하기위해서 각 항목을 구분할 수 있도록 key값을 정의해야함

* App에서 상태를 정의하고 하위컴포넌트에서 props를 이용하여 사용한다.

 

* 실습결과 - 링크를 클릭하면 /content/ 폴더아래 key에 해당하는 자원이 표시됨

#13 React - 13. React Developer Tools

 

* chrome 플러그인으로 지원하는 react 개발자 도구

** 영상에서 설명하는 개발자도구 접근방법 (없어짐)

 - reactjs.org > community > tools > Debugging

 > React Developer Tools - Chrome, Fierfox, standalone app 지원

** 개선된 크롬 디버그 툴 제공

 - 관련 블로그 글 : https://ko.reactjs.org/blog/2019/08/15/new-react-devtools.html

 > https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en 

 

React Developer Tools

Adds React debugging tools to the Chrome Developer Tools. Created from revision 0ae5290b54 on 5/25/2021.

chrome.google.com

 

* 개발자 도구 사용

 - HTML 소스 확인 : Elements 탭

 - react 구조 확인 : Components 탭

 

* 영상에서는 Components 탭에서 html 소스를 기반으로 컴포넌트 정보가 표시되었지만, 개선된 개발자도구에서는 트리구조로 표시됨

- 화면 정보를 실시간으로 변경하거나, props 의 정보를 수정해가며 확인할 수 있음

(확인) Chrome 플러그인 React Developer Tools 설치 시 Elements, Components 탭이 보이지 않으면

 - Chrome > 설정 > 확장프로그램 > React Developer Tools > 세부정보

 > '파일 URL에 대한 액세스 허용' 항목 체크

 

#14 React - 14. Component 파일로 분리하기

 

* App.js 에 정의된 컴포넌트를 별도의 파일로 분리

** 참고

 - index.js 에서 <APP/> 테그로 선언한 컴포넌트를

   같은 경로의 App.js 파일로 구현된 기능으로 컴포넌트 적용

 > import App from './App'; 

** TOC 컴포넌트 분리

 - 폴더및 대상 소스파일 생성

 > /componets/TOC.js

 - 구현소스 이동 : App.js(TOC 소스) > TOC.js

 > Componet 사용을 위해 import 추가 : TOC.js

 > Toc 컴포넌트 참조를 위해 export 추가 : TOC.js

import { Component } from 'react';
class Toc extends Component{
    render(){
      return(
        <nav>
          <ul>
            <li><a href="1.html">HTML</a></li>
            <li><a href="2.html">CSS</a></li>
            <li><a href="3.html">JavaScript</a></li>
          </ul>
      </nav>
      );
    }
  }
  export default Toc;

 - 소스 이동에 따른 호출부 현행화

 > TOC 소스 위치 import 문 추가 : App.js

import Toc from './components/TOC';

* 이동 결과

* 나머지 컴포넌트 분리

 - Subject, Article

** 응용1 : refactor 를 이용한 추출

 - 코드블럭 : class 선언 영역

 - 마우스 우클릭 팝업메뉴 : Refactor [Ctrl+Shift+R]

 - Move to a new file

 - src/Subject.js 로 생긴 파일 이동 : src/componets/Subject.js

 - Update imorts for 'Subject.js'

 - Subject.js 파일에서 클래스명 선택 후 Refactor : Convert named export to default export

 

import './App.css';
import Toc from './components/TOC';
import React, { Component } from 'react';
import Subject from './components/Subject';

class Article extends Component{
 ...
}

class App extends Component {
  render(){
  return (
    <div className="App">
    <Subject title="WEB1" sub="WWW!!"></Subject>
    <Subject title="WEB2" sub="React JSX."></Subject>
    <Toc></Toc>
    <Article title="HTML" desc="HTML is HyperText Markup Loanguage."></Article>
    </div>
  );
  }
}

export default App;

import React, { Component } from 'react';

export default class Subject extends Component {
  render() {
    return (
      <header>
        <h1>{this.props.title}</h1>
        {this.props.sub}
      </header>
    );
  }
}

 - Article - Refactor : Convert named export to default export 없이 이동

import './App.css';
import Toc from './components/TOC';
import React, { Component } from 'react';
import Subject from './components/Subject';
import { Article } from './components/Article';

class App extends Component {
  render(){
  return (
    <div className="App">
    <Subject title="WEB1" sub="WWW!!"></Subject>
    <Subject title="WEB2" sub="React JSX."></Subject>
    <Toc></Toc>
    <Article title="HTML" desc="HTML is HyperText Markup Loanguage."></Article>
    </div>
  );
  }
}

export default App;

import React, { Component } from 'react';

export class Article extends Component {
  render() {
    return (
      <article>
        <h2>HTML</h2>
        {this.props.desc}
      </article>
    );
  }
}

어라.. 에러가 나네.

 - 파일 이동 후 바로 새로고침을 하면 오류가 발생한다.

 > 호출파일과 이동파일을 다시 저장하면 빌드시간을 거쳐 다시 정상적으로 표시되는것 같다. ㅋ

 : Failed to compile

 Error : ENOENT :  no such file or directory, open '대상소스경로'

 

#10 React - 10. 리액트가 없다면

 

* 웹화면 구성시 복잡도를 관리하기 위한 react의 기능 확인

 - 셈플 웹페이지 작성 (복잡도를 높히기 위해 시멘틱 테그 적용)

<html>
    <body>
        <h1>WEB</h1>
        Word Wide Web!
        <ul>
            <li><a href="1.html">HTML</a></li>
            <li><a href="2.html">CSS</a></li>
            <li><a href="3.html">JavaScript</a></li>
        </ul>
        <h2>HTML</h2>
        HTML is HyperText Markup Loanguage.
    </body>
</html>
<html>
    <body>
        <header>
            <h1>WEB</h1>
            Word Wide Web!
        </header>
        <nav>
            <ul>
                <li><a href="1.html">HTML</a></li>
                <li><a href="2.html">CSS</a></li>
                <li><a href="3.html">JavaScript</a></li>
            </ul>
        </nav>
        <article>
            <h2>HTML</h2>
            HTML is HyperText Markup Loanguage.
        </article>
    </body>
</html>

 

#11.1 React - 11.1. 컴포넌트 만들기 1

 

* 준비 - 기본 컴포넌트 구성

// import logo from './logo.svg'; // 삭제
import './App.css';
import { Component } from 'react';

class App extends Component {
  render(){
  return (
    <div className="App">
    hello, jkoogi
    </div>
  );
  }
}

export default App;
- 불필요한 선언구문 삭제 (삭제하지 않으면 compile 경고)
- 스타일 정의파일 추가
- react의 component 추가

- react의 Component 클래스를 상속받은 App 클래스 정의
- Component 클래스의 render() 메서드 정의
- render() 메서드에서 반환할 text 정의(html 코드)
- return 되는 html 코드는 하나의 테그로 래핑되어야 함
- 표시될 내용
- 래핑 테그 종료




- 반환할 응답 클래스

* 추가 컴포넌트 구성 : 클래스명 첫글자는 대문자

class Subject extends Component{
  render(){
    return(
      <header>
        <h1>WEB</h1>
        Word Wide Web!
      </header>
    );
  }
}


class App extends Component {
  render(){
  return (
    <div className="App">
    <Subject></Subject>
    </div>
  );
  }
}
- react의 Component 클래스를 상속받은 추가 클래스 정의

- render() 메서드에서 반환할 내용 : header html 코드
> 응답하는 html 코드는
escape 문자를 이용하여 문자열로 구성하는
번거로움이 없도록
jsx(페이스북에서 제공)라는 언어로 코드를 작성하고,
create-react-app에서 javascript로 변환해준다.

(구현한 함수는 javascript가 아님
- 디버그에서 console에 적용해보면 문법오류 발생)



- create-react-app 서비스의 index에 표시될 내용으로 적용



- 저장하면 바로 적용됨.

#11.2 React - 11.2. 컴포넌트 만들기 2

 

* 나머지 컴포넌트 전환

class Toc extends Component{
  render(){
    return(
      <nav>
        <ul>
          <li><a href="1.html">HTML</a></li>
          <li><a href="2.html">CSS</a></li>
          <li><a href="3.html">JavaScript</a></li>
        </ul>
    </nav>
    );
  }
}

class Article extends Component{
  render(){
    return(
      <article>
        <h2>HTML</h2>
        HTML is HyperText Markup Loanguage.
      </article>
    );
  }
}

class App extends Component {
  render(){
  return (
    <div className="App">
    <Subject></Subject>
    <Toc></Toc>
    <Article></Article>
    </div>
  );
  }
}
- Toc 클래스 등록













Article 컴포넌트 클래스 등록















- Toc 컴포넌트 적용
- Article 컴포넌트 적용



 

#12 React - 12. props

 

- 복잡도를 해결하기 위해 컴포넌트를 이용하여 단순화 시켰으나, 비슷한 다른기능을 적용하기 위해 속성을 적용하여 활용성을 확장한다.

 

* porps

 - https://reactjs.org/docs/components-and-props.html#function-and-class-components

 

class Subject extends Component{
  render(){
    return(
      <header>
        <h1>{this.props.title}</h1>
        {this.props.sub}
      </header>
    );
  }
}

class App extends Component {
  render(){
  return (
    <div className="App">
    <Subject title="WEB1" sub="WWW!!"></Subject>
    <Subject title="WEB2" sub="React JSX."></Subject>
    <Toc></Toc>
    <Article></Article>
    </div>
  );
  }
}




- 컴포넌트의 속성 적용
- 컴포넌트의 속성 적용
> title의 값과 sub의 값이 Subject 컴포넌트의 
  입력값으로 적용되어 출력값을 다르게 표시함







- 컴포넌트의 속성 사용
- 컴포넌트의 속성 사용

 

#7 React - 7. JS 코딩하는 법

 

* 디랙토리 구조

** public : 배포파일 폴더

 - public\index.html (첫화면) : react 로 만든 앱을 root 에 적용하도록 구성됨

 > root 영역에 적용될 개발 결과물은 src의 소스로 구성됨

<div id="root"></div>

** src : 소스파일 폴더

 - 진입파일 : index.js

 >  root 테그에 App 컴포넌트를 적용한다.

import App from './App'; -- ./App.js 파일

ReactDOM.render(
  <React.StrictMode>
    <App /> -- react로 만든 컴포넌트
  </React.StrictMode>,
  document.getElementById('root')
);

- App.js 파일 변경 : 함수방식 > 클래스방식

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

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;

import logo from './logo.svg';
import './App.css';
import { Component } from 'react';

class App extends Component {
  render(){
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
  }
}

export default App;

 - 편집 테스트

import logo from './logo.svg';
import './App.css';
import { Component } from 'react';

class App extends Component {
  render(){
  return (
    <div className="App">
    hello, jkoogi
    </div>
  );
  }
}

export default App;


<div className="App"> 테그를 지우면 에러 !!

 

#8 React - 8. CSS 코딩하는 법

* App.js

import './index.css';

* src\index.css

body {
  margin0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI''Roboto''Oxygen',
    'Ubuntu''Cantarell''Fira Sans''Droid Sans''Helvetica Neue',
    sans-serif;
  -webkit-font-smoothingantialiased;
  -moz-osx-font-smoothinggrayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}
# 기존코드 수정
body {
  background-colorpowderblue;
}

 
 
 

 

#9 React - 9. 배포하는 법

 

* 브라우저 캐시 삭제 : 1.8M 용량 배포

 - npm run start 실행모드

- 실행 정지

 - npm run build 배포소스 빌드

 > build 폴더와 함께 배포소스 생성 : 경량화, 난독화 적용

PS D:\dev\workspace.react> npm run build

> workspace.react@0.1.0 build D:\dev\workspace.react
> react-scripts build

Creating an optimized production build...
Compiled with warnings.

src\App.js
  Line 1:8:  'logo' is defined but never used  no-unused-vars

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

File sizes after gzip:

  41.83 KB  build\static\js\2.0ba32bae.chunk.js
  1.63 KB   build\static\js\3.dc217ad5.chunk.js
  1.17 KB   build\static\js\runtime-main.c92287a2.js
  527 B     build\static\js\main.0f932358.chunk.js
  397 B     build\static\css\main.778564b4.chunk.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment

PS D:\dev\workspace.react>

* 배포 서비스 실행 :  npm 으로 설치하는 간단한 웹서버

 - npm install -g serve : 전역 서버 실행

 - npx serve -s build : serve 를 한번만 다운로드하여 실행할 때 -s 로 정의한 경로(build)를 root 로 실행 : 113B 용량

서비스 배포 : npx serve -s build
접속경로 : http://localhost:5000

#4 React - 4. npm을 이용해서 create react app 설치

 

* npm 설치 (14.17.1 LTS) - https://nodejs.org/ko/

  - https://nodejs.org/ko/download/

  - windows portable x64 설치 : 압축해제 하고 NODE_HOME을 환경변수에 등록해서 path를 추가했다.

  > NODE_HOME : D:\dev\bin\node-v14.17.1-win-x64 , path : %NODE_HOME%;

   (지식정보사이트 : 서말 > NPM1 : npm을 다루는 기본방법)

 

* create-react-app 설치

 - 공식문서 가이드 : npx (임시로 설치해서 한번만 실행하고 지움 : 최신버전, 공간절약 장점)

D:\dev\bin\node-v14.17.1-win-x64>npm install -g create-react-app
D:\dev\bin\node-v14.17.1-win-x64\create-react-app -> D:\dev\bin\node-v14.17.1-win-x64\node_modules\create-react-app\index.js
+ create-react-app@4.0.3
added 67 packages from 25 contributors in 5.302s

D:\dev\bin\node-v14.17.1-win-x64>create-react-app -V
4.0.3

D:\dev\bin\node-v14.17.1-win-x64>

 

#5 React - 5. create react app을 이용해서 개발환경구축

 

* 개발환경 구성

 - D:\dev\workspace.react

D:\dev\workspace.react>create-react-app .

Creating a new React app in D:\dev\workspace.react.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...


> core-js@2.6.12 postinstall D:\dev\workspace.react\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@3.14.0 postinstall D:\dev\workspace.react\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js-pure@3.14.0 postinstall D:\dev\workspace.react\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> ejs@2.7.4 postinstall D:\dev\workspace.react\node_modules\ejs
> node ./postinstall.js

+ cra-template@1.1.2
+ react-scripts@4.0.3
+ react@17.0.2
+ react-dom@17.0.2
added 1899 packages from 703 contributors and audited 1902 packages in 237.642s

145 packages are looking for funding
  run `npm fund` for details

found 8 vulnerabilities (4 moderate, 4 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Initialized a git repository.

Installing template dependencies using npm...
npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5 requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ web-vitals@1.1.2
+ @testing-library/user-event@12.8.3
+ @testing-library/react@11.2.7
+ @testing-library/jest-dom@5.14.1
added 29 packages from 78 contributors and audited 1931 packages in 19.933s

145 packages are looking for funding
  run `npm fund` for details

found 8 vulnerabilities (4 moderate, 4 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Removing template package using npm...

npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5 requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

removed 1 package and audited 1930 packages in 6.83s

145 packages are looking for funding
  run `npm fund` for details

found 8 vulnerabilities (4 moderate, 4 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Git commit not created Error: Command failed: git commit -m "Initialize project using Create React App"
    at checkExecSyncError (child_process.js:643:11)
    at execSync (child_process.js:679:15)
    at tryGitCommit (D:\dev\workspace.react\node_modules\react-scripts\scripts\init.js:62:5)
    at module.exports (D:\dev\workspace.react\node_modules\react-scripts\scripts\init.js:352:25)
    at [eval]:3:14
    at Script.runInThisContext (vm.js:134:12)
    at Object.runInThisContext (vm.js:311:38)
    at internal/process/execution.js:77:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60) {
  status: 128,
  signal: null,
  output: [ null, null, null ],
  pid: 19028,
  stdout: null,
  stderr: null
}
Removing .git directory...

Success! Created workspace.react at D:\dev\workspace.react
Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd D:\dev\workspace.react
  npm start

Happy hacking!

D:\dev\workspace.react>

 

#6 React - 6. 샘플 웹앱 실행

 

* Visual Studio Code를 이용한 실행

 - terminal 실행 : npm run start / 종료 : Ctrl+C

 

 

 

#1 React - 1. 수업소개

생활코딩 react 강의를 들으며 정리해본다.

 - 선행 강의 : web to javascript, javascript object oriented programming(객체간의 상속 강의까지)

 

react : 페이스북에서 만듬

 - 재사용성을 위해 앱구조를 테그로 관리하도록 지원하는 라이브러리

 > 가독성, 재사용성, 유지보수 용이성 지원

 

#2 React - 2. 공부 전략

* 집중사항 : 코딩, 실행, 배포

 

#3 React - 3. 개발환경의 종류

* 공식사이트 :  https://ko.reactjs.org/

 - Get Started

* react 실행방법

** Online Playgrounds : 테스트 서비스

  https://ko.reactjs.org/docs/getting-started.html#online-playgrounds

 - https://codesandbox.io/s/new

 

** Add React to a Website : 기존 웹사이트에 react 적용(부분 적용)

 - 개발환경 구축이 어려움

** Create a New React App : 툴체인으로 목표를 구성하기 위한 개발환경, 도구 모음

  https://reactjs.org/docs/getting-started.html#create-a-new-react-app

 - learn how : https://reactjs.org/docs/create-a-new-react-app.html

 - 추천 툴체인 : Create React App

 > https://reactjs.org/docs/create-a-new-react-app.html#recommended-toolchains

*** Create React APP (앱의 이름)

 - https://reactjs.org/docs/create-a-new-react-app.html#create-react-app

 > app의 소스코드 주소 : https://github.com/facebook/create-react-app

npx create-react-app my-app
cd my-app
npm start

- npm 프로그램을 설치하여 로컬에 create-react-app 설치
> npm : node.js 기술로 만들어진 여러 앱을 명령어 환경에서 설치해주는 프로그램

previwe - npm 설치, create-react-app 설치, 개발환경 구성 #4

 

 

 

 

 

+ Recent posts