LoginSignup
1
0

More than 5 years have passed since last update.

react

Last updated at Posted at 2018-08-08

react 어제 연습해보고 오늘 다시 연습할려고 하는데 잠시동안 당황했다
어떻게 해야하지??
요즘들어서 느끼는 거지만 머리로 이해하는것만이 전부는 아닌듯 하다.
실습하고 몸에 베이도록 하는것
이론만 안다고 되는것은 아니다.

create-react-app //react 서버 실행

cd hello-react //해당 프로젝트 폴더이동

npm start //npm start
MyName.js
import React, {Component} from 'react';

class MyName extends Component {
  /* 첫번째 방법
   * static defaultProps = {
   *   name: '기본이름'
   * }
   */
  render() {
    return (
      <div>
        hello my name is <b>{this.props.name}</b> 입니다.
      </div>
      );
  }
}
// 두번째 방법
MyName.defaultProps = {
  name : '기본이름'
};

export default MyName;
App.js
import React, { Component } from 'react';
import MyName from './MyName';
import './App.css';

class App extends Component {
  render() {
    return (
        <MyName />
    );
  }
}

export default App;

함수형 컴포넌트

MyName.js
import React from 'react';

const MyName = ({name}) => {
  return (
    <div>
    hello, MyName is {name} 입니다.
    </div>
    );
}

MyName.defaultProps = {
  name : '기본이름'
};

export default MyName;
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0