Help us understand the problem. What is going on with this article?

[react:day1] Reactをはじめます&デバッグ環境も

More than 1 year has passed since last update.

環境

os: mac
editor: vs code

動機

react nativeを使いたい。ならまずはreactから手を出すか!

reactアプリのgeneratorをinstall

# generatorをinstall(facebook製だよ)
npm install -g create-react-app

# installが終わったらreactアプリをgenerete. my-appという名前のアプリ
create-react-app my-app

my-appディレクトリが作成されているので移動 & server起動

cd my-app

# server start
npm start

tips

npm startはpackage.jsonの scripts startを呼び出している

package.json
{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "1.1.0"
  },
  "scripts": {
    "start": "react-scripts start", # ⇦これを呼び出している
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

サーバーが立ち上がればこの画面が表示される
スクリーンショット 2018-01-30 15.13.05.png

Hello, world

index.jsを以下のように書き換える

index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

var element = React.createElement('h1', { className: 'greeting'}, 'Hello, world')
ReactDOM.render(element, document.getElementById('root'));
registerServiceWorker();

saveすると画面が変わる
スクリーンショット 2018-01-30 15.17.21.png

vs codeでデバッグできるように設定ファイルを作成する

launch_json_create.gif

こんな感じでデバッグできるようになる
debug_start.gif

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away