{"id":6084,"date":"2021-04-16T14:16:42","date_gmt":"2021-04-16T05:16:42","guid":{"rendered":"https:\/\/learningbox.co.jp\/?p=6084"},"modified":"2021-04-16T14:32:56","modified_gmt":"2021-04-16T05:32:56","slug":"blog_react-hooks-tetris","status":"publish","type":"post","link":"https:\/\/learningbox.co.jp\/en\/2021\/04\/16\/blog_react-hooks-tetris\/","title":{"rendered":"I used React to make Tetris for company training."},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01\u6700\u8fd1\u958b\u767a\u90e8\u306b\u5165\u3063\u305f\u6a4b\u672c\u3067\u3059\u3002<br \/>\n\u5f0a\u793e\u306e\u958b\u767a\u90e8\u306b\u5165\u308b\u3068\u884c\u3046\u7814\u4fee\u306e 1 \u3064\u306b\u300cJavaScript \u3092\u4f7f\u3063\u305f\u4f55\u304b\u3092\u4f5c\u308b\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u50d5\u306f React \u3092\u4f7f\u3063\u3066\u30c6\u30c8\u30ea\u30b9\u3092\u4f5c\u3063\u305f\u306e\u3067\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p class=\"mokujimidasi\">\u76ee\u6b21\u306f\u3053\u3061\u3089<\/p>\n<ul class=\"mokuji\">\n<li>1. React \u3092\u4f7f\u3063\u3066\u4f5c\u6210\u3057\u305f\u30c6\u30c8\u30ea\u30b9<\/li>\n<li>2. \u30c6\u30c8\u30ea\u30b9\u3092\u4f5c\u308b\u969b\u306b\u4f7f\u7528\u3057\u305f\u6280\u8853<\/li>\n<li>3. \u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u89e3\u8aac<\/li>\n<li>4. \u307e\u3068\u3081<\/li>\n<\/ul>\n<h2>React \u3092\u4f7f\u3063\u3066\u4f5c\u6210\u3057\u305f\u30c6\u30c8\u30ea\u30b9<\/h2>\n<p><a href=\"https:\/\/hideyuk1-jp.github.io\/react-hooks-tetris\/\">\u3053\u3061\u3089<\/a>\u3067\u5b9f\u969b\u306b\u904a\u3076\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\uff08\u753b\u9762\u53f3\u4e0a\u306e\u97f3\u58f0\u30a2\u30a4\u30b3\u30f3\u3092\u62bc\u3059\u3068\u00a0BGM\u00a0\u3084\u52b9\u679c\u97f3\u304c\u6d41\u308c\u307e\u3059\uff09<\/p>\n<p>\u3060\u3044\u305f\u3044\u30c6\u30c8\u30ea\u30b9\u3089\u3057\u3044\u3082\u306e\u304c\u51fa\u6765\u305f\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f<a href=\"https:\/\/github.com\/hideyuk1-jp\/react-hooks-tetris\">\u3053\u3061\u3089<\/a>\u304b\u3089\u78ba\u8a8d\u51fa\u6765\u307e\u3059\u306e\u3067\u3001\u7d30\u304b\u3044\u5b9f\u88c5\u90e8\u5206\u307e\u3067\u898b\u305f\u3044\u65b9\u306f\u3069\u3046\u305e\u3002<\/p>\n<h2> \u30c6\u30c8\u30ea\u30b9\u3092\u4f5c\u308b\u969b\u306b\u4f7f\u7528\u3057\u305f\u6280\u8853<\/h2>\n<p class=\"well\">&#8211; React<br \/>\n&#8211; TypeScript<br \/>\n&#8211; Chakra UI\u200b<\/p>\n<p>JavaScript \u3055\u3048\u4f7f\u3063\u3066\u3044\u308c\u3070\u3069\u3093\u306a\u6280\u8853\u3092\u4f7f\u3063\u3066\u3082 OK \u3068\u3044\u3046\u81ea\u7531\u306a\u7814\u4fee\u3060\u3063\u305f\u306e\u3067\u3001\u5f0a\u793e\u306e\u958b\u767a\u3067\u3082\u63a1\u7528\u3055\u308c\u3066\u3044\u308b <strong>React<\/strong> \u3068 <strong>TypeScript<\/strong>\u3001\u305d\u3057\u3066\u30b9\u30bf\u30a4\u30eb\u306b\u306f\u500b\u4eba\u7684\u306b\u4f7f\u3063\u3066\u307f\u305f\u304b\u3063\u305f <strong>Chakra UI<\/strong> \u3092\u4f7f\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f\u00a0React\u00a016.8\u00a0\u3067\u8ffd\u52a0\u3055\u308c\u305f\u00a0Hooks\u00a0\u3082\u7a4d\u6975\u7684\u306b\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u307e\u3057\u305f\u3002<br \/>\n\u753b\u9762\u63cf\u753b\u306f\u3088\u304f\u4f7f\u308f\u308c\u308b canvas \u306f\u4f7f\u308f\u305a\u306b\u3001React \u306e state \u66f4\u65b0\u3060\u3051\u3067\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u89e3\u8aac<\/h2>\n<p>\u7d30\u304b\u3044\u3068\u3053\u308d\u306f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3082\u3089\u3046\u3068\u3057\u3066\u3001\u30b2\u30fc\u30e0\u306b\u3064\u3044\u3066\u3056\u3063\u304f\u308a\u3068\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3>\u753b\u9762\u69cb\u6210<\/h3>\n<p>4 \u3064\u306e\u753b\u9762\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<table style=\"width: 100%;border-collapse: collapse\" border=\"1\">\n<tbody>\n<tr>\n<th style=\"width: 50%\">\u753b\u9762<\/th>\n<th style=\"width: 50%\">\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">\u30a4\u30f3\u30c8\u30ed<\/td>\n<td style=\"width: 50%\">\u6700\u521d\u306b\u8868\u793a\u3055\u308c\u308b\u753b\u9762\u3002Start \u30dc\u30bf\u30f3\u62bc\u4e0b\u3067\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u753b\u9762\u3078\u5207\u308a\u66ff\u3048<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3<\/td>\n<td style=\"width: 50%\">\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u3057\u3066 0 \u4ee5\u4e0b\u306b\u306a\u3063\u305f\u3089\u30b9\u30c6\u30fc\u30b8\u753b\u9762\u3078\u5207\u308a\u66ff\u3048<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">\u30b9\u30c6\u30fc\u30b8<\/td>\n<td style=\"width: 50%\">\u30b2\u30fc\u30e0\u672c\u4f53\u306e\u753b\u9762\u3002\u30b2\u30fc\u30e0\u30aa\u30fc\u30d0\u30fc\u3067\u30ea\u30b6\u30eb\u30c8\u753b\u9762\u3078\u5207\u308a\u66ff\u3048<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">\u30ea\u30b6\u30eb\u30c8<\/td>\n<td style=\"width: 50%\">\u30b9\u30b3\u30a2\u3092\u8868\u793a\u3059\u308b\u753b\u9762\u3002Retry \u30dc\u30bf\u30f3\u62bc\u4e0b\u3067\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u753b\u9762\u3078\u5207\u308a\u66ff\u3048<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u753b\u9762\u306e\u5207\u308a\u66ff\u3048\u306f\u00a0<strong>scene<\/strong> \u3068\u3044\u3046 state \u3092\u4f5c\u6210\u3057\u3066\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>        {scene === \"intro\" ? (\r\n          &lt;Intro onClickStart={() =&gt; setScene(\"countDown\")} \/&gt;\r\n        ) : scene === \"countDown\" ? (\r\n          &lt;CountDown\r\n            onCountOvered={() =&gt; setScene(\"stage\")}\r\n            isSoundOn={isSoundOn}\r\n          \/&gt;\r\n        ) : scene === \"stage\" ? (\r\n          &lt;Stage onGameOvered={handleGameOvered} isSoundOn={isSoundOn} \/&gt;\r\n        ) : (\r\n          scene === \"result\" &amp;&amp; (\r\n            &lt;Result score={score} onClickRetry={() =&gt; setScene(\"countDown\")} \/&gt;\r\n          )\r\n        )}<\/pre>\n<h3>\u30b2\u30fc\u30e0\u672c\u4f53\u90e8\u5206\u306e\u51e6\u7406\u306e\u6d41\u308c<\/h3>\n<p>\u30b9\u30c6\u30fc\u30b8\u753b\u9762\u306b\u9077\u79fb\u3059\u308b\u3068\u3001\u81ea\u52d5\u7684\u306b\u30c6\u30c8\u30ea\u30b9\u304c\u59cb\u307e\u308a\u307e\u3059\u3002<\/p>\n<p class=\"well\">1. \u30bf\u30fc\u30f3\u958b\u59cb<br \/>\n2. \u30ad\u30fc\u30dc\u30fc\u30c9\u64cd\u4f5c\u3067\u843d\u3061\u30d6\u30ed\u30c3\u30af\u3092\u4e0b\u5de6\u53f3\u306b\u79fb\u52d5\u307e\u305f\u306f\u56de\u8ee2\u3002\u4e00\u5b9a\u6642\u9593\u3054\u3068\u306b\u843d\u4e0b<br \/>\n3. \u843d\u3061\u30d6\u30ed\u30c3\u30af\u304c\u4e0b\u307e\u3067\u843d\u3061\u304d\u308b<br \/>\n4. \u30b2\u30fc\u30e0\u30aa\u30fc\u30d0\u30fc\u306e\u5224\u5b9a\uff08\u30b2\u30fc\u30e0\u30aa\u30fc\u30d0\u30fc\u306e\u5834\u5408\u3001\u30ea\u30b6\u30eb\u30c8\u753b\u9762\u3078\u9077\u79fb\uff09<br \/>\n5. \u843d\u3061\u30d6\u30ed\u30c3\u30af\u3092\u53cd\u6620\u3057\u305f\u76e4\u9762\u3092\u6e96\u5099<br \/>\n6. \u6d88\u3048\u308b\u884c\u306e\u5224\u5b9a<br \/>\n7. \u6d88\u3048\u305f\u884c\u306e\u6570\u306b\u5fdc\u3058\u3066\u6210\u7e3e\u66f4\u65b0<br \/>\n8. \u884c\u3092\u6d88\u3057\u305f\u3042\u3068\u306e\u76e4\u9762\u3092\u6e96\u5099<br \/>\n9. \u6b21\u306e\u843d\u3061\u30d6\u30ed\u30c3\u30af\u3092\u6e96\u5099<br \/>\n10. \u76e4\u9762\u3001\u843d\u3061\u30d6\u30ed\u30c3\u30af\u3001\u6b21\u306e\u843d\u3061\u30d6\u30ed\u30c3\u30af\u3092\u66f4\u65b0<br \/>\n11. \u6b21\u306e\u30bf\u30fc\u30f3\u958b\u59cb<\/p>\n<p>\u4e0a\u8a18\u306e\u4e00\u9023\u306e\u51e6\u7406\u3092 1 \u30bf\u30fc\u30f3\u3068\u3057\u3066\u3001<strong>turnState<\/strong> \u3068\u3044\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e state \u3092\u4f5c\u3063\u3066\u8907\u6570\u306e\u72b6\u614b\u3092\u7ba1\u7406\u3057\u306a\u304c\u3089\u30bf\u30fc\u30f3\u9032\u884c\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u304c turnState \u3092\u521d\u671f\u5316\u3057\u3066\u3044\u308b\u90e8\u5206\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>  const [turnState, setTurnState] = useState({\r\n    field: [...Array(FIELD_SIZE.rows * FIELD_SIZE.columns)],\r\n    dropBlock: createBlock(),\r\n    nextDropBlock: createBlock(),\r\n    isDropped: false,\r\n  });<\/pre>\n<p>\u305d\u308c\u305e\u308c\u3069\u3046\u3044\u3046\u60c5\u5831\u3092\u7ba1\u7406\u3057\u3066\u3044\u308b\u304b\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse;width: 100%\" border=\"1\">\n<tbody>\n<tr>\n<th style=\"width: 50%\">\u30ad\u30fc<\/th>\n<th style=\"width: 50%\">\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">field<\/td>\n<td style=\"width: 50%\">\u76e4\u9762\u306e\u60c5\u5831\uff08\u3069\u306e\u5ea7\u6a19\u306b\u4f55\u8272\u306e\u30d6\u30ed\u30c3\u30af\u304c\u3042\u308b\u304b\uff09\u3092\u683c\u7d0d<br \/>\n\u843d\u3061\u30d6\u30ed\u30c3\u30af\u306f\u843d\u3061\u304d\u3063\u305f\u3042\u3068\u306b\u3053\u3053\u306b\u53cd\u6620\u3055\u308c\u308b<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">dropBlock<\/td>\n<td style=\"width: 50%\">\u73fe\u5728\u306e\u843d\u3061\u30d6\u30ed\u30c3\u30af\u306e\u60c5\u5831\u3092\u683c\u7d0d\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<br \/>\n&#8211; \u843d\u3061\u30d6\u30ed\u30c3\u30af\u306e\u30b5\u30a4\u30ba\uff08\u5168\u3066 4 x 4 \u3067\u3059\u304c\u4e00\u5fdc\uff09<br \/>\n&#8211; \u5de6\u4e0a\u306e\u5ea7\u6a19\uff08\u79fb\u52d5\u3059\u308b\u3068\u5909\u308f\u308b\uff09<br \/>\n&#8211; \u3069\u306e\u5ea7\u6a19\u306b\u4f55\u8272\u306e\u30d6\u30ed\u30c3\u30af\u304c\u3042\u308b\u304b\uff08\u56de\u8ee2\u3059\u308b\u3068\u5909\u308f\u308b\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">nextDropBlock<\/td>\n<td style=\"width: 50%\">\u6b21\u306e\u843d\u3061\u30d6\u30ed\u30c3\u30af\u306e\u60c5\u5831\u3092\u683c\u7d0d\uff08\u683c\u7d0d\u3059\u308b\u60c5\u5831\u306e\u7a2e\u985e\u306f dropBlock \u3068\u540c\u3058\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%\">isDropped<\/td>\n<td style=\"width: 50%\">\u843d\u3061\u30d6\u30ed\u30c3\u30af\u304c\u843d\u3061\u304d\u3063\u305f\u304b\u3069\u3046\u304b\u306e\u30d5\u30e9\u30b0\u3002\u3053\u308c\u3092\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u3067\u30bf\u30fc\u30f3\u958b\u59cb\u3068\u7d42\u4e86\u306e\u51e6\u7406\u3092\u884c\u3046<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u308c\u3089\u306e\u72b6\u614b\u3092\u90fd\u5ea6\u66f4\u65b0\u3057\u3066\u3044\u304f\u3053\u3068\u3067\u30b2\u30fc\u30e0\u304c\u52d5\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u4ee5\u4e0a\u3001\u300c\u4f1a\u793e\u306e\u7814\u4fee\u3067 React \u4f7f\u3063\u3066\u30c6\u30c8\u30ea\u30b9\u4f5c\u3063\u3066\u307f\u305f\u300d\u3067\u3057\u305f\uff01<br \/>\nReact \u3067\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u305f\u306e\u306f\u521d\u3081\u3066\u3060\u3063\u305f\u306e\u3067\u63cf\u753b\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u308a\u3057\u3066\u82e6\u6226\u3057\u307e\u3057\u305f\u304c\u3001\u306a\u3093\u3068\u306a\u304f\u4f7f\u3063\u3066\u3044\u305f Hooks \u306b\u3064\u3044\u3066\u3082\u6539\u3081\u3066\u8abf\u3079\u305f\u308a\u3057\u3066\u826f\u3044\u52c9\u5f37\u306b\u306a\u3063\u305f\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f Chakra UI \u3092\u4f7f\u3063\u305f\u30b9\u30bf\u30a4\u30ea\u30f3\u30b0\u3082\u6163\u308c\u3066\u304f\u308b\u3068\u30b5\u30af\u30b5\u30af\u66f8\u3044\u3066\u3044\u3051\u308b\u306e\u3067\u3001\u5225\u306e\u6a5f\u4f1a\u306b\u3082\u4f7f\u3063\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u3002<br \/>\n\u7686\u3055\u3093\u3082\u3088\u304b\u3063\u305f\u3089\u00a0React\u00a0\u3067\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"\u3053\u3093\u306b\u3061\u306f\uff01\u6700\u8fd1\u958b\u767a\u90e8\u306b\u5165\u3063\u305f\u6a4b\u672c\u3067\u3059\u3002 \u5f0a\u793e\u306e\u958b\u767a\u90e8\u306b\u5165\u308b\u3068\u884c\u3046\u7814\u4fee\u306e 1 \u3064\u306b\u300cJavaScript \u3092\u4f7f [&hellip;]","protected":false},"author":1,"featured_media":6125,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"vkexunit_cta_each_option":"","footnotes":""},"categories":[6,7,40],"tags":[50,66],"class_list":["post-6084","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-7","category-40","tag-javascript","tag-react"],"acf":[],"jetpack_featured_media_url":"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/04\/react-hooks-tetris.jpg","jetpack_shortlink":"https:\/\/wp.me\/pgMrZ4-1A8","_links":{"self":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/comments?post=6084"}],"version-history":[{"count":52,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6084\/revisions"}],"predecessor-version":[{"id":6139,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/6084\/revisions\/6139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media\/6125"}],"wp:attachment":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media?parent=6084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/categories?post=6084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/tags?post=6084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}