Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?

More than 3 years have passed since last update.

@ozepon

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

環境

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

11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  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
11
Help us understand the problem. What is going on with this article?