1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React デバッグ方法

Last updated at Posted at 2020-06-02

Debugger for Chrome

設定方法・手順

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}/src",
      "sourceMapPathOverrides": {
        "webpack:///src/*": "${webRoot}/*"
      }
    }
  ]
}

ソースコードにブレークポイントを指定

yarn startにてローカル環境を起動

デバッグツールを起動

React Developer Tools

  • componentタブでstateとpropsが確認できる

*参考
https://qiita.com/sh-suzuki0301/items/9c2af4b28ba665cc0744

Redux DevTools

  • Redux-sagaだとデバックが可能(redux-thunkだと動かない)

  • top層のindex.tsxに以下の内容を記載 (src/index.tsx(index.jsx))

    • これを記載しないとRedux DevToolsが動かない
import { applyMiddleware, compose, createStore } from 'redux';

/* eslint-disable no-underscore-dangle, @typescript-eslint/no-explicit-any */
const composeEnhancers =
  process.env.NODE_ENV === 'development' &&
  typeof window === 'object' &&
  (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
    ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
    : compose;
/* eslint-enable */

const enhancer = composeEnhancers(applyMiddleware(sagaMiddleWare));
const store = createStore(reducer, enhancer);
1
2
0

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?