{"id":13621,"date":"2021-06-20T08:26:33","date_gmt":"2021-06-19T23:26:33","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13621"},"modified":"2023-05-27T22:08:05","modified_gmt":"2023-05-27T13:08:05","slug":"%e3%80%90react%e3%80%91%e3%80%8creact-router-dom%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13621","title":{"rendered":"\u3010React\u3011\u57fa\u672c(\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3001\u8a2d\u5b9a\u3001Error Boundary\u306a\u3069)\u3001\u300creact-router\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u6982\u8981<\/h2>\n<p>2013\u306b\u516c\u958b\u3055\u308c\u30662017\u5e74\u306b\u30e9\u30a4\u30bb\u30f3\u30b9\u3092\u5f97\u3066\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u30e9\u30a4\u30bb\u30f3\u30b9\u306b\u53d7\u3051\u5165\u308c\u3089\u308c\u307e\u3057\u305f\u3002Facebook\u793e\u304c\u958b\u767a\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u7279\u5fb4<\/h2>\n<p>\u4eee\u60f3DOM\u306e\u63a1\u7528\u3067\u9ad8\u901f\u3067\u52d5\u4f5c\u3059\u308b\u3002<\/p>\n<h2>\u63a1\u7528\u4e8b\u4f8b<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b5\u30fc\u30d3\u30b9\u3067\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>facebook<\/li>\n<li>Udemy<\/li>\n<li>Slack<\/li>\n<li>Qiita<\/li>\n<li>NETFLIX<\/li>\n<li>Airbnb<\/li>\n<\/ul>\n<h2>\u30d0\u30fc\u30b8\u30e7\u30f3<\/h2>\n<table style=\"width: 916px;\">\n<tbody>\n<tr>\n<th style=\"width: 48px;\">\u30d0\u30fc\u30b8\u30e7\u30f3<\/th>\n<th style=\"width: 89.9141px;\">\u30ea\u30ea\u30fc\u30b9\u65e5<\/th>\n<th style=\"width: 683.086px;\">\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">15<\/td>\n<td style=\"width: 89.9141px;\"><\/td>\n<td style=\"width: 683.086px;\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">16<\/td>\n<td style=\"width: 89.9141px;\">2017\u5e749\u6708<\/td>\n<td style=\"width: 683.086px;\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">16.3<\/td>\n<td style=\"width: 89.9141px;\">2018\u5e743\u6708<\/td>\n<td style=\"width: 683.086px;\">\u30fbReact18\u3067\u5c0e\u5165\u4e88\u5b9a\u306econcurrent rendering\u306b\u5099\u3048\u3066\u300cStrict mode\u300d\u304c\u5b9f\u88c5\u3055\u308c\u305f\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">16.8<\/td>\n<td style=\"width: 89.9141px;\">2019\u5e742\u6708<\/td>\n<td style=\"width: 683.086px;\">ReactHooks\u304c\u767b\u5834\u3057\u305f\u3002React\u5358\u54c1\u3067\u72b6\u614b\u7ba1\u7406\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">17<\/td>\n<td style=\"width: 89.9141px;\">2020\u5e7411\u6708<\/td>\n<td style=\"width: 683.086px;\">\u30fb\u65b0\u6a5f\u80fd\u306f\u306a\u3044<\/p>\n<p>\u30fb2\u5e74\u534a\u3076\u308a\u306e\u30e1\u30b8\u30e3\u30fc\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 48px;\">18<\/td>\n<td style=\"width: 89.9141px;\">2022\u5e743\u6708<\/td>\n<td style=\"width: 683.086px;\">\u30fb\u958b\u767a\u30e2\u30fc\u30c9\u304b\u3064Strict mode\u6709\u52b9\u6642\u306b Bug\u3092\u691c\u51fa\u3057\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b\u3001<wbr \/>React\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u521d\u56de\u306b2\u56de\u30de\u30a6\u30f3\u30c8\u3059\u308b\u4ed5\u69d8\u306b\u5909\u66f4<wbr \/>\u306b\u306a\u3063\u3066\u3044\u308b\u3002\uff08production\u30e2\u30fc\u30c9\u3067\u306f\u305d\u3046\u3067\u306f\u306a\u3044\uff09<\/p>\n<p>\u2192\u306a\u306e\u3067\u958b\u767a\u30e2\u30fc\u30c9\u306e\u6642\u306b\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u56de\u6570\u3092\u3061\u3083\u3093\u3068\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408\u306fStrict mode\u3092\u5916\u3059\u306e\u304c\u826f\u3044\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>boilerplate<\/h2>\n<h3>create-react-app<\/h3>\n<p>Facebook\u793e\u304c\u958b\u767a\u3057\u305f\u6700\u3082\u6709\u540d\u306aboilerplate\u3067\u3059\u3002babel\u3084webpack\u3068\u304b\u304c\u5185\u5305\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h4>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h4>\n<p>\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3067boilerplate\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">yarn global add create-react-app<\/pre>\n<p>\u307e\u305f\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">create-react-app react-test<\/pre>\n<p>\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">npx create-react-app react-starter<\/pre>\n<h4>npx\u30b3\u30de\u30f3\u30c9<\/h4>\n<p>\u30ed\u30fc\u30ab\u30eb\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304b\u3089\u5b9f\u884c\u3057\u3066\u304f\u308c\u308b\u30b3\u30de\u30f3\u30c9<\/p>\n<h4>\u4f5c\u6210\u3055\u308c\u308b\u30d5\u30a1\u30a4\u30eb<\/h4>\n<table>\n<tbody>\n<tr>\n<th>\u30d5\u30a1\u30a4\u30eb\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>README.md<\/td>\n<td>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/td>\n<\/tr>\n<tr>\n<td>node_modules<\/td>\n<td>\u958b\u767a\u74b0\u5883\u3084\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea<\/td>\n<\/tr>\n<tr>\n<td>package.json<\/td>\n<td>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u60c5\u5831\u304c\u8a18\u8ff0\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>public<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u251cfavicon.ico<\/td>\n<td>\u30d5\u30a1\u30d3\u30b3\u30f3\u753b\u50cf<\/td>\n<\/tr>\n<tr>\n<td>\u251cindex.html<\/td>\n<td>\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u3066\u8868\u793a\u3055\u308c\u308b\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>\u251clogo192.png<\/td>\n<td>PWA\u306e\u30a2\u30a4\u30b3\u30f3\u753b\u50cf<\/td>\n<\/tr>\n<tr>\n<td>\u251clogo512.png<\/td>\n<td>PWA\u306e\u30a2\u30a4\u30b3\u30f3\u753b\u50cf<\/td>\n<\/tr>\n<tr>\n<td>\u251cmanifest.json<\/td>\n<td>PWA\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>\u2514robots.txt<\/td>\n<td>Google\u30af\u30ed\u30fc\u30e9\u306a\u3069\u306e\u30af\u30ed\u30fc\u30eb\u3092\u5236\u5fa1\u3059\u308b\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>src<\/td>\n<td>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u69cb\u6210\u3059\u308b\u30d5\u30a1\u30a4\u30eb\uff08\u958b\u767a\u6642\u306f\u307b\u307c\u3053\u3053\u3092\u3044\u3058\u308b\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u251cApp.css<\/td>\n<td>App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30b9\u30bf\u30a4\u30eb\u304c\u5b9a\u7fa9\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>\u251cApp.js<\/td>\n<td>App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u5b9a\u7fa9\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>\u251cApp.test.js<\/td>\n<td>App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/td>\n<\/tr>\n<tr>\n<td>\u251cindex.js<\/td>\n<td>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30f3\u30c8\u30ea\u30dd\u30a4\u30f3\u30c8\uff08\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u251cindex.css<\/td>\n<td>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5171\u901a\u306e\u30b9\u30bf\u30a4\u30eb\u304c\u5b9a\u7fa9\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td>\u251clogo.svg<\/td>\n<td>\u30ed\u30b4\u753b\u50cf<\/td>\n<\/tr>\n<tr>\n<td>\u251creportWebVitals.js<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u2514setupTests.js<\/td>\n<td>\u30c6\u30b9\u30c8\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u52d5\u304b\u3059\u3002<\/h4>\n<p>\u8d77\u52d5<\/p>\n<pre class=\"lang:default decode:true \">yarn run start<\/pre>\n<p>\u4e0b\u8a18URL\u3067\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost:3000<\/pre>\n<h2>package.json<\/h2>\n<h3>scripts<\/h3>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\"scripts\": {\r\n    \"start\": \"react-scripts start\",\r\n    \"build\": \"react-scripts build\",\r\n    \"test\": \"react-scripts test\",\r\n  },<\/pre>\n<h4>test<\/h4>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u300cnpm test\u300d\u3092\u5b9f\u884c\u3057\u305f\u969b\u306b<span style=\"color: #ff0000;\"><strong>\u8907\u6570\u30b1\u30fc\u30b9\u30c6\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u305f\u3068\u3057\u3066\u3082\u3001\u5404\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306e\u8a73\u7d30\u307e\u3067\u51fa\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\"test\": \"react-scripts test --env=jsdom --verbose\"<\/pre>\n<h2>setupTests.ts<\/h2>\n<p>\u300ccreate-react-app\u300d\u306b\u304a\u3051\u308bJest\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u306a\u308a\u307e\u3059\u3002\u3082\u3057\u3001\u30c6\u30b9\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306bEnzyme\u306a\u3069\u3092\u4f7f\u3046\u5834\u5408\u306f\u3053\u3061\u3089\u306b\u8a2d\u5b9a\u3092\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h2>Error Boundary\u3068\u306f\uff1f<\/h2>\n<p>Error Boundary \u3068\u3044\u3046\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30c4\u30ea\u30fc\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u30af\u30e9\u30c3\u30b7\u30e5\u3057\u305f UI \u3092\u8868\u793a\u3055\u305b\u308b\u4ee3\u308f\u308a\u306b\u3001\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u7528\u306e UI \u3092\u8868\u793a\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002React16\u4ee5\u964d\u306f\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3068\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30c4\u30ea\u30fc\u304c\u5168\u3066\u30a2\u30f3\u30de\u30a6\u30f3\u30c8\u3055\u308c\u3066\u3057\u307e\u3046\u6319\u52d5\u306b\u306a\u3063\u305f\u305f\u3081\u51fa\u3066\u304d\u305f\u6982\u5ff5\u3067\u3059\u3002\uff0815\u4ee5\u524d\u306f\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u3066\u3082\u767d\u753b\u9762\u306b\u306a\u3089\u306a\u304b\u3063\u305f\u3002\uff09<\/p>\n<h2>\u4f7f\u3046\u306b\u306f\uff1f<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u306f\u30af\u30e9\u30b9\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u306a\u3051\u308c\u3070\u4f7f\u3048\u306a\u304b\u3063\u305f\u3002\u305f\u3060\u3001React\u306f\u6628\u4eca\u4e3b\u6d41\u306b\u306a\u308a\u3064\u3064\u3042\u308bFunctional Component\u3067\u3082Error Boundary\u3092\u4f7f\u3048\u308b\u300creact-error-boundary\u300d\u3068\u3044\u3046\u30e9\u30c3\u30d1\u30fc\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u3002<\/p>\n<h2>React-router\u3068\u306f\uff1f<\/h2>\n<p>React\u3067SPA\u306b\u3088\u308b\u30da\u30fc\u30b8\u9077\u79fb\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<h2>\u7279\u5fb4<\/h2>\n<p>\u30d6\u30e9\u30a6\u30b6\u306e\u5c65\u6b74\u306b\u3082\u84c4\u7a4d\u3055\u308c\u308b\u306e\u3067\u30d6\u30e9\u30a6\u30b6\u30d0\u30c3\u30af \u3068\u304b\u3082\u666e\u901a\u306b\u884c\u3048\u307e\u3059\u3002<\/p>\n<h2>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<pre class=\"lang:default decode:true\">npm install  react-router-dom<\/pre>\n<h2>react-router-dom<\/h2>\n<h3>Link<\/h3>\n<p>SPA\u30ea\u30f3\u30af\u3092\u8a2d\u5b9a\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<h3>withRouter<\/h3>\n<p>withRouter\u3092\u4f7f\u3048\u3070\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3067\u30da\u30fc\u30b8\u9077\u79fb\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true  \">this.props.history.push('\u9077\u79fb\u5148\u306e\u30d1\u30b9')<\/pre>\n","protected":false},"excerpt":{"rendered":"\u6982\u8981 2013\u306b\u516c\u958b\u3055\u308c\u30662017\u5e74\u306b\u30e9\u30a4\u30bb\u30f3\u30b9\u3092\u5f97\u3066\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u30e9\u30a4\u30bb\u30f3\u30b9\u306b\u53d7\u3051\u5165\u308c\u3089\u308c\u307e\u3057\u305f\u3002Facebook\u793e\u304c\u958b\u767a\u3057\u307e\u3057\u305f\u3002 \u7279\u5fb4 \u4eee\u60f3DOM\u306e\u63a1\u7528\u3067\u9ad8\u901f\u3067\u52d5\u4f5c\u3059\u308b\u3002 \u63a1\u7528\u4e8b\u4f8b \u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b5\u30fc\u30d3\u30b9\u3067\u63a1\u7528\u3055\u308c\u3066 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[116],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13621"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13621"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13621\/revisions"}],"predecessor-version":[{"id":20421,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13621\/revisions\/20421"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13621"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}