반응형

 

이번에는 아이템 추가하는 기능을 구현해보도록 하겠습니다.

 

1. 신규요소 (Control.js) 추가

각 링크에는 onClick 이벤트 요소를 선언하고 onChangeMode함수와 연결을 해 줍니다. 이때, 모드를 인자로 넘겨줍니다.

import React, { Component } from 'react';

class Control extends Component {
    render() {
        return (
            <ul>
                <li>
                    <a href="/create" onClick={function (e) {   // onChangeMode 함수 연결
                        e.preventDefault();
                        this.props.onChangeMode('create');
                    }.bind(this)}>create</a>
                </li>
                <li>
                    <a href="/update" onClick={function (e) {   // onChangeMode 함수 연결
                        e.preventDefault();
                        this.props.onChangeMode('update');
                    }.bind(this)}>update</a>
                </li>
                <li>
                    <input onClick={function (e) {      // onChangeMode 함수 연결
                        e.preventDefault();
                        this.props.onChangeMode('delete');
                    }.bind(this)} type="button" value="delete"></input>
                </li>
            </ul>
        );
    }
}

export default Control;

2. 신규요소(CreateContent.js) 추가

신규 생성시 입력폼을 작성합니다. 폼은 아래 그림의 아래부분과 같이 구성되어 있습니다. 이때 onSubmit 함수로 title 과 desc 값이 전달될 수 있도록 아래와 같이 코딩을 합니다.

import React, { Component } from 'react';

class CreateContent extends Component {
    render() {
        return (
            <div>
                <article>
                    <h2>Create</h2>
                    <form action="/create_process" method="post"
                        onSubmit={function (e) {
                            e.preventDefault();
                            this.props.onSubmit(
                                e.target.title.value,
                                e.target.desc.value
                            );
                        }.bind(this)}
                    >
                        <p><input type="text" name="title" placeholder="title"></input></p>
                        <p><textarea name="desc" placeholder="description"></textarea></p>
                        <p><input type="submit"></input></p>
                    </form>
                </article>
            </div>
        );
    }
}

export default CreateContent;

3. App.js 수정

  - 새로 작성한 Control, CreateContent 컴포넌트를 임포트하고,

  - welcome, read, create, ... 모드에 따라 content를 다르게 보여주도록 _article 변수를 활용하도록 코딩을 수정하고,

  - CreateContent 컴포넌트(2번)에서 title, desc 입력 후 Submit 시 기존 content에 데이터 추가되는 부분 수정한다.

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import ReadContent from './components/ReadContent'; // Content -> ReadContent로 변경
import CreateContent from './components/CreateContent'; // CreateContent 추가
import Control from './components/Control';
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.max_content_id = 3;  // 초기값으로 content의 값과 같이 설정함. ui와 전혀 상관이 없는 속성은 state의 외부에 선언
    this.state = {
      mode: 'create',
      selected_content_id: 2,
      welcome: { title: 'welcom', desc: 'Hello, React!!' },
      subject: { title: 'WEB', sub: 'world wide web!' },
      contents: [
        { id: 1, title: 'HTML', desc: 'HTML is HyperText ...' },
        { id: 2, title: 'CSS', desc: 'CSS is for design' },
        { id: 3, title: 'Javascript', desc: 'JavaScript is for interactive' }
      ]
    }
  }
  render() {
    var _title, _desc, _article = null;   // _article 선언. mode(welcome, read, create) 에 따라서 다른 출력
    if (this.state.mode === 'welcome') {
      _title = this.state.welcome.title;
      _desc = this.state.welcome.desc;
      _article = <ReadContent title={_title} desc={_desc}></ReadContent>  // welcome 모드에서의 표시
    } else if (this.state.mode === 'read') {
      var i = 0;
      while (i < this.state.contents.length) {
        var data = this.state.contents[i];
        if (data.id === this.state.selected_content_id) {
          _title = data.title;
          _desc = data.desc;
          break;
        }
        i = i + 1;
      }
      _article = <ReadContent title={_title} desc={_desc}></ReadContent>  // read 모드에서의 표시
    } else if (this.state.mode === 'create') {
      // 'create'모드일 경우 <CreateContent> 요소를 표시
      _article = <CreateContent onSubmit={function (_title, _desc) {      // _title, _desc를 인자로 받는다.
        this.max_content_id = this.max_content_id + 1;
        var newContents = Array.from(this.state.contents)                // 기존 content 복사하여 새 배열 생성
        newContents.push({ id: this.max_content_id, title: _title, desc: _desc })         // 기존 배열에 새로운 값 추가        
        this.setState({
          contents: newContents   // 기존 contents 값을 _contents 값으로 교체 대입해준다.
        })
      }.bind(this)}></CreateContent>
    }
    return (
      <div className="App">
        <Subject
          title={this.state.subject.title}
          sub={this.state.subject.sub}
          onChangePage={function () {
            this.setState({ mode: 'welcome' });
          }.bind(this)}
        />

        <TOC
          onChangePage={function (id) {
            this.setState({
              mode: 'read',
              selected_content_id: Number(id)
            });
          }.bind(this)}
          data={this.state.contents} />

        <Control
          onChangeMode={function (_mode) {  // 모드를 인자로 받아서 전달해준다.
            this.setState({
              mode: _mode
            })
          }.bind(this)} />

        {/*<ReadContent title={_title} desc={_desc} />   삭제*/}
        {_article} {/* content를 create/read 에 따라 다르게 보여줄 새 요소 */}
      </div>
    );
  }
}


export default App;

 

4. TOC.js 수정

shouldComponentUpdate() 함수를 이용하여, 매 변경시마다 무조건 렌더링 되는것을 막는 코드를 추가합니다.

import React, { Component } from 'react';

class TOC extends Component {
    // 매 변경시마다 관계없는 요소들을 모두 렌더하는 것을 막아주는 기능 구현
    shouldComponentUpdate(newProps, newState) { // newProps.data는 바뀐 데이터, this.props.data는 기존 데이터
        if (newProps.data === this.props.data) {    // 바뀐 값이 있다면
            return false;                           // 렌더함수 호출 안함
        }                                           // 그 이외에는 
        return true;                                // 렌더함수 호출

    }
    render() {
        var lists = [];
        var data = this.props.data;
        var i = 0;
        while (i < data.length) {
            lists.push(
                <li key={data[i].id}>
                    <a
                        href={"/content/" + data[i].id}
                        data-id={data[i].id}
                        onClick={function (e) {
                            e.preventDefault();
                            this.props.onChangePage(e.target.dataset.id);
                        }.bind(this)}
                    >{data[i].title}</a></li>);
            i = i + 1;
        }
        return (
            <div>
                <nav>
                    <ul>
                        {lists}
                    </ul>
                </nav>
            </div>
        );
    }
}

export default TOC;

- 끝 - 

반응형

'Programming > React' 카테고리의 다른 글

React기초- 9.Delete  (0) 2020.07.29
React기초- 8.Update  (0) 2020.07.29
React기초- 6.이벤트  (0) 2020.07.28
React기초-5.state2  (0) 2020.07.27
React기초-4.state  (0) 2020.07.25
반응형

이번 시간에는 클릭 이벤트에 대해 Content가 변경되도록 App을 구성해보겠습니다.

 

1. 아래 화면에서 WEB을 클릭하면 그 아래 HTML / HTML is HyperText Markup Language 부분이 그에 맞는 내용으로 변경되게 할 것입니다.

 

우선 WEB 부분에 해당하는 <h1> 영역에 링크를 달아줍니다.

 

Subject.js

import React, { Component } from 'react';

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

export default Subject;

 

페이지 첫 로딩시와 WEB을 클릭하면 웰컴페이지가 나타나도록 하기 위해 state에 'mode'를 생성하고,

welcome 모드에서 보여줄 내용을 'welcome' 인자를 생성합니다.

render()함수 내부에 _title, _desc 변수를 선언해주고 모드에 따른 내용이 변경되도록 할당해줍니다.

그리고 <Content> 컴포넌트의 내용에 전달되도록 코드를 수정해줍니다.

 

App.js

<Subject> 태그 내부에 onChangePage 속성을 선언하고 실행할 함수를 정의해줍니다. 이 함수는 mode를 'welcome'으로 변경해줍니다.

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      mode: 'read',  // 읽기모드인지 welcome모드인지 구분하는 '모드' 설정
      welcome: { title: 'welcom', desc: 'Hello, React!!' }, // welcome모드에서 표시할 내용 선언
      subject: { title: 'WEB', sub: 'world wide web!' },
      contents: [
        { id: 1, title: 'HTML', desc: 'HTML is HyperText ...' },
        { id: 2, title: 'CSS', desc: 'CSS is for design' },
        { id: 3, title: 'Javascript', desc: 'JavaScript is for interactive' }
      ]
    }
  }
  render() {
    var _title, _desc = null;
    if (this.state.mode === 'welcome') {  // welcome 모드일 경우
      _title = this.state.welcome.title;  // welcome 의 title
      _desc = this.state.welcome.desc;    // welcome 의 desc
    } else if (this.state.mode === 'read') {  // read 모드일 경우
      _title = this.state.contents[0].title;  // 1번째 content의 title: 추후 개선 예정
      _desc = this.state.contents[0].desc;    // 1번째 content의 desc: 추후 개선 예정
    }
    return (
      <div className="App">
        <Subject
          title={this.state.subject.title}
          sub={this.state.subject.sub}
          onChangePage={function () {
            this.setState({ mode: 'welcome' });
          }.bind(this)}
        />

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

        <Content title={_title} desc={_desc} /> {/* mode에 따라 타이틀과 desc를 전달받는다. */}
      </div>
    );
  }
}


export default App;

 

Subject.js

<a> 태그 내부에 클릭 이벤트 속성인 onClick으로 onChangePage()함수를 연결해줍니다.

import React, { Component } from 'react';

class Subject extends Component {
    render() {
        return (
            <div>
                <header>
                    <h1><a href="/" onClick={function (e) {
                        e.preventDefault();
                        this.props.onChangePage();
                    }.bind(this)}>{this.props.title}</a></h1>
                    {this.props.sub}
                </header>
            </div>
        );
    }
}

export default Subject;

 

2. 다음으로 HTML / CSS / JavaScript부분을 클릭하면 역시 내용이 변경되도록 해보겠습니다.

 

App.js

<TOC> 태그 내부에 마찬가지로 onChangePage 함수를 선언해줍니다.

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

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      mode: 'read',
      selected_content_id: 2,  // 기본적으로 2번이 선택되도록 함
      welcome: { title: 'welcom', desc: 'Hello, React!!' },
      subject: { title: 'WEB', sub: 'world wide web!' },
      contents: [
        { id: 1, title: 'HTML', desc: 'HTML is HyperText ...' },
        { id: 2, title: 'CSS', desc: 'CSS is for design' },
        { id: 3, title: 'Javascript', desc: 'JavaScript is for interactive' }
      ]
    }
  }
  render() {
    var _title, _desc = null;
    if (this.state.mode === 'welcome') {
      _title = this.state.welcome.title;
      _desc = this.state.welcome.desc;
    } else if (this.state.mode === 'read') {  // read 모드일 경우
      var i = 0;                                // 반복을 위한 i 변수를 선언하고
      while (i < this.state.contents.length) {    // i 가 content의 요소 갯수만큼 반복하며
        var data = this.state.contents[i];    // i 번째 content를 data 라고 정의한다.
        if (data.id === this.state.selected_content_id) { // data의 id와 현재 선택된 content의 id가 일치할 경우
          _title = data.title;  // content의 title을 다음 진행(출력)으로 넘겨준다.
          _desc = data.desc;    // content의 desc을 다음 진행(출력)으로 넘겨준다.
          break;
        }
        i = i + 1;
      }
    }
    return (
      <div className="App">
        <Subject
          title={this.state.subject.title}
          sub={this.state.subject.sub}
          onChangePage={function () {
            this.setState({ mode: 'welcome' });
          }.bind(this)}
        />

        <TOC
          onChangePage={function (id) {         // 몇번째 요소인지를 id로 넘겨받아서 실행한다.
            this.setState({
              mode: 'read',                     // 모드를 read로 바꿔준다.
              selected_content_id: Number(id)   // selected_content_id에 넘겨받은 id값을 할당하면서 숫자형으로 변환한다.
            });
          }.bind(this)}
          data={this.state.contents} />

        <Content title={_title} desc={_desc} />
      </div>
    );
  }
}


export default App;

 

TOC.js

<a> 태그 내부에 onClick 이벤트 함수를 지정해줍니다.

import React, { Component } from 'react';

class TOC extends Component {
    render() {
        var lists = [];
        var data = this.props.data;
        var i = 0;
        while (i < data.length) {
            lists.push(
                <li key={data[i].id}>
                    <a
                        href={"/content/" + data[i].id}
                        data-id={data[i].id}       // 몇번째 요소의 이벤트인지를 나타내는 id 
                        			  // 'data-XXX'접두사로 시작하는 속성은 e.target.dataset.XXX으로 접근가능하다.
                        onClick={function (e) {                              
                            e.preventDefault();
                            			  // onChangePage()함수를 연결하면서 id값을 넘겨준다.
                            this.props.onChangePage(e.target.dataset.id);  
                        }.bind(this)}
                    >{data[i].title}</a></li>);
            i = i + 1;
        }
        return (
            <div>
                <nav>
                    <ul>
                        {lists}
                    </ul>
                </nav>
            </div>
        );
    }
}

export default TOC;
반응형

'Programming > React' 카테고리의 다른 글

React기초- 8.Update  (0) 2020.07.29
React기초- 7.Create  (0) 2020.07.29
React기초-5.state2  (0) 2020.07.27
React기초-4.state  (0) 2020.07.25
React기초-3.props  (0) 2020.07.25
반응형

여러개의 list를 state로 선언 후 하위 컴포넌트에 전달하는 방법.

 

App.js

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      subject: { title: 'WEB', sub: 'world wide web!' },
      contents: [
        { id: 1, title: 'HTML', desc: 'HTML is HyperText ...' },
        { id: 2, title: 'CSS', desc: 'CSS is for design' },
        { id: 3, title: 'Javascript', desc: 'JavaScript is for interactive' }
      ]
    }
  }
  render() {
    return (
      <div className="App">
        <Subject
          title={this.state.subject.title}
          sub={this.state.subject.sub}
        />

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

        <Content title="HTML" desc="HTML is HyperText Markup Language." />
      </div>
    );
  }
}


export default App;

App.js 에서는 TOC 컴포넌트의 data(props)로 정보(this.state.contents)를 전달합니다.

 

TOC.js

import React, { Component } from 'react';

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

export default TOC;

TOC 컴포넌트 내부에서는 props의 형태로 받아들인 데이터를 data라는 변수로 받아들이고 이를 활용합니다. 출력할 때에는 while루프에 의해 생성된 lists만 출력하면 결과가 나타납니다. 여러개의 리스트를 생성할 경우 key 값이 필요한 점도 익혀두시기 바랍니다.

 

반응형

'Programming > React' 카테고리의 다른 글

React기초- 7.Create  (0) 2020.07.29
React기초- 6.이벤트  (0) 2020.07.28
React기초-4.state  (0) 2020.07.25
React기초-3.props  (0) 2020.07.25
React기초-2.컴포넌트 제작  (0) 2020.07.25
반응형

오늘은 state에 대해서 알아보도록 하겠습니다.

Props가 Component를 조작하기 위해 사용자에게 제공하는 속성이라고 하면, state는 외부(상위) 사용자가 모르는 component 내부적으로 사용하는 속성입니다.

 

아래는 state의 예시입니다. 

 

App.js(Old)

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <Subject title="WEB" sub="world wide web!" />

        <TOC />

        <Content title="HTML" desc="HTML is HyperText Markup Language." />
      </div>
    );
  }
}


export default App;

기존 Subject 컴포넌트에서 props에 해당하는 title, sub 속성이 고정되어 있었습니다. 이를 조작 가능하도록 상위 컴포넌트에 해당하는 App에서 변수의 형태로 선언을 하려고 합니다. 이 경우 App 내부에서 변수와 같이 활용 가능한 속성을 state라고 합니다. 이렇게 App의 state로 선언된 속성을 하위 컴포넌트인 Subject의 props로 전달하여 변경하도록 하겠습니다.

 

App.js(New)

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      subject: { title: 'WEB', sub: 'world wide web!' }
    }
  }
  render() {
    return (
      <div className="App">
        <Subject
          title={this.state.subject.title}
          sub={this.state.subject.sub}
        />

        <TOC />

        <Content title="HTML" desc="HTML is HyperText Markup Language." />
      </div>
    );
  }
}


export default App;

 위와 같이 App 컴포넌트 내부에서 변수와 같이 사용할 속성을 선언할 때에는 this.state로 선언하고,

이를 하위 컴포넌트의 props로(title, sub) 할당하여 사용할 수 있습니다. 이렇게 선언하면 아직은 고정된 text를 출력하지만, 추후에는 App 컴포넌트 내부에서 state의 조작을 통해 Subject로 전달되는 정보를 변경할 수 있게 됩니다.

 

반응형

'Programming > React' 카테고리의 다른 글

React기초- 6.이벤트  (0) 2020.07.28
React기초-5.state2  (0) 2020.07.27
React기초-3.props  (0) 2020.07.25
React기초-2.컴포넌트 제작  (0) 2020.07.25
React기초-1.설치 및 환경설정  (0) 2020.07.25
반응형

 

오늘은 props에 대해 알아보겠습니다. props는 사용자가 생성한 component의 속성(attribute)를 말합니다. 예를 들어 아래의 코드에서 사용자가 생성한 <Subject> 컴포넌트 내부에 title, sub과 같은 사용자 정의 속성을 부여할 경우 이것들을 props라고 합니다.

 

App.js

import React, { Component } from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

class App extends Component {
	render(){
      return (
        <div className="App">
          {/* 기존코드
          <Subject />
          */}
          <Subject title="WEB" sub="world wide web!" />

          <TOC />

          <Content title="HTML" desc="HTML is HyperText Markup Language." />
        </div>
      );
    }
}

export default App;

 

Subject.js

import React, { Component } from 'react';

class Subject extends Component {
    render() {
        return (
            <div>
                <header>
                    {/* 기존 코드
                    <h1>WEB</h1>
                    world wide web
                    */}
                    <h1>{this.props.title}</h1>
                    {this.props.sub}
                </header>
            </div>
        );
    }
}

export default Subject;

위의 예에서 보듯이 기존에는 Subject.js에서 직접 태크와 텍스트로 그려내던 것을

App.js 내에서 Subject 컴포넌트의 title, sub와 같은 속성(props)으로 정의한 다음,

다시 Subject.js에서 이 속성(props)를 위의 코드와 같은 형식으로 불러서 출력할 수 있습니다.

 

이후 과제 진행을 위해서 Content.js도 props 속성을 이용하여 수정하도록 하겠습니다.

 

Content.js

import React, { Component } from 'react';

class Content extends Component {
    render() {
        return (
            <div>
                <article>
                    <h2>{this.props.title}</h2>
                    {this.props.desc}
                </article>
            </div>
        );
    }
}

export default Content;
반응형

'Programming > React' 카테고리의 다른 글

React기초- 6.이벤트  (0) 2020.07.28
React기초-5.state2  (0) 2020.07.27
React기초-4.state  (0) 2020.07.25
React기초-2.컴포넌트 제작  (0) 2020.07.25
React기초-1.설치 및 환경설정  (0) 2020.07.25
반응형

컴포넌트 제작으로부터 시작해보겠습니다. 강좌에 의하면 React의 가장 기초적인 기능이 HTML 문서가 장대해질 경우 component를 별도 구성함으로써 코드를 단순화/정리정돈하는 기능이라고 합니다. 이것 만으로도 뭔가 React를 사용하고 있다는 느낌이 드네요.

 

1. 우선 App.js에서 <div className="App"> 태그 사이의 내용을 지우고 아래의 내용으로 교체해 넣습니다.

logo.svg파일을 임포트 하는 부분도 삭제해 줍니다.

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

class App extends Component {
	render(){
        return (
          <div className="App">
            <header> {/*Subjct Component */}
              <h1>WEB</h1>
              world wide web!
            </header>

            <nav>{/*TOC Component */}
              <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>{/*Content Component */}
              <h2>HTML</h2>
              HTML is HyperText Markup Language.
            </article>
          </div>
        );
    }
}

export default App;

 결과물은 아래와 같이 나타나게 됩니다.

 

 

 

2. 다음으로 <header>, <nav>, <article> 부분을 이용하여 각각 Subject.js , TOC.js, Content.js component를 만듭니다. component들은 components라는 폴더를 만들고 그 내부에 생성합니다. (빈 편집창에서 rcc라고 치고 엔터를 치면 Class형 component 양식을 자동 구성해줍니다.)

 

 

 

Subject.js

import React, { Component } from 'react';

class Subject extends Component {
    render() {
        return (
            <div>
                <header>
                    <h1>WEB</h1>
                    world wide web!
                </header>
            </div>
        );
    }
}

export default Subject;

TOC.js

import React, { Component } from 'react';

class TOC extends Component {
    render() {
        return (
            <div>
                <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>
            </div>
        );
    }
}

export default TOC;

content.js

import React, { Component } from 'react';

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

export default Content;

3. App.js를 작성한 component를 이용하여 재구성합니다.

  - 각각의 컴포넌트들을 import 해주고

  - 각각의 컴포넌트들을 불러와 사용해준다.

import React from 'react';
import Subject from './components/Subject';
import TOC from './components/TOC';
import Content from './components/Content';
//import logo from './logo.svg'; 삭제
import './App.css';

function App() {
  return (
    <div className="App">
      <Subject />

      <TOC />

      <Content />
    </div>
  );
}

export default App;

 결과물이 최초 화면과 동일하게 나온다면 컴포넌트가 정상적으로 생성된 것으로 볼 수 있겠네요.

 

- 끝 - 

반응형

'Programming > React' 카테고리의 다른 글

React기초- 6.이벤트  (0) 2020.07.28
React기초-5.state2  (0) 2020.07.27
React기초-4.state  (0) 2020.07.25
React기초-3.props  (0) 2020.07.25
React기초-1.설치 및 환경설정  (0) 2020.07.25
반응형

React로 이런거 한번 만들어보겠습니다.

 

egoing님 강좌 따라하기입니다. 방송으로만 보면 기억에 안남아서 공부할 겸 남겨놓습니다.

 

기능은

1. 로딩시 또는 WEB을 클릭하면 welcome 화면 띄우기

2. 각 Subject(HTML / CSS / JavaScript)를 클릭하면 그에 따른 내용 변경하기

3. create Subject

4. update Subject

5. delete Subject

입니다.

 

 

 

 

1. 우선적으로 설치해야할 것은

1. Node 
2. Visual Studio Code 
3. create-react-app (npm install -g create-react-app : global 설치)

입니다.

 

2. Visual Studio Code에 필요한 부가기능은

1. reactjs code snippets 설치
2. Pretter 설치

를 하면 좀 더 편리하게 작업할 수 있습니다.

3. create-react-app 시작하기

1. 작업폴더 생성

2. 터미널에서 해당 폴더로 이동하여 아래 명령어 수행(현재 디렉토리에 react 앱 설치)

C:\react_lec2> create-react-app .

 

4. 확인

C:\react_lec2> npm run start 

React 시작화면이 잘 작동합니다. 이제 React를 시작할 준비가 되었습니다.

 

- 끝 -

반응형

'Programming > React' 카테고리의 다른 글

React기초- 6.이벤트  (0) 2020.07.28
React기초-5.state2  (0) 2020.07.27
React기초-4.state  (0) 2020.07.25
React기초-3.props  (0) 2020.07.25
React기초-2.컴포넌트 제작  (0) 2020.07.25

+ Recent posts