{"id":3485,"date":"2022-08-03T18:58:08","date_gmt":"2022-08-03T09:58:08","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3485"},"modified":"2022-08-12T13:06:53","modified_gmt":"2022-08-12T04:06:53","slug":"%e3%80%90react%e3%80%91%e3%82%b9%e3%83%86%e3%83%bc%e3%83%88%e3%81%ab%e3%82%88%e3%82%8b%e3%83%87%e3%83%bc%e3%82%bf%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3485","title":{"rendered":"\u3010React\u3011\u30b9\u30c6\u30fc\u30c8\u306b\u3088\u308b\u30c7\u30fc\u30bf\u66f4\u65b0"},"content":{"rendered":"\n<p>\u4eca\u307e\u3067\u306f\u56fa\u5b9a\u306e\u6587\u5b57\u3092\u30d6\u30e9\u30a6\u30b6\u3078\u8868\u793a\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u524d\u56de<\/span>\n<p><\/p>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=3449\" rel=\"noopener\" target=\"_blank\">\u3010React\u3011\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3078\u5024\u3092\u6e21\u3059<\/a><\/p>\n<\/div>\n\n\n\n<p>\u4eca\u56de\u306f\u30d6\u30e9\u30a6\u30b6\u3078\u52d5\u7684\u306b\u6587\u5b57\u3092\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8aac\u660e<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">React\u306b\u304a\u3051\u308b\u30b9\u30c6\u30fc\u30c8\u51e6\u7406\u306e\u6982\u8981<\/h2>\n\n\n\n<p>React\u306b\u306f\u30b9\u30c6\u30fc\u30c8\u3068\u8a00\u3046\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3001\u66f4\u65b0\u3059\u308b\u6a5f\u80fd\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30c8\u306f\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3057\u3001\u305d\u308c\u3092\u66f4\u65b0\u3059\u308b\u4e8b\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u306e\u8868\u793a\u5185\u5bb9\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b9\u30c6\u30fc\u30c8\u51e6\u7406\u306e\u4f7f\u3044\u65b9\u3068\u8aac\u660e<\/h2>\n\n\n\n<p>\u30b9\u30c6\u30fc\u30c8\u3092\u4f7f\u3046\u306b\u306f useState \u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ \u30b9\u30c6\u30fc\u30c8\nconst [val, setVal] = React.useState(&#39;first&#39;);<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u95a2\u6570\u306e\u5f15\u6570\u306b\u306f\u4fdd\u6301\u3057\u305f\u3044\u30c7\u30fc\u30bf\u306e\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u304b\u3089\u914d\u5217\u304c\u8fd4\u5374\u3055\u308c\u3001\u7b2c\u4e00\u8981\u7d20\u306fuseState\u95a2\u6570\u3067\u6307\u5b9a\u3057\u305f\u5f15\u6570\u306e\u5024\u304c\u8fd4\u5374\u3055\u308c\u307e\u3059\u3002\u7b2c\u4e8c\u8981\u7d20\u306f\u8a2d\u5b9a\u5024\u3092\u66f4\u65b0\u3059\u308b\u95a2\u6570\u304c\u8fd4\u5374\u3055\u308c\u307e\u3059\u3002<br>\u8a2d\u5b9a\u5024\u3092\u66f4\u65b0\u3059\u308b\u95a2\u6570\u3078\u8a2d\u5b9a\u3057\u305f\u3044\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u73fe\u5728\u306e\u8a2d\u5b9a\u5024\u304c\u66f4\u65b0\u3055\u308c\u3001\u753b\u9762\u306b\u8868\u793a\u3055\u308c\u308b\u5185\u5bb9\u304c\u5909\u66f4\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5b9f\u4f8b<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u3084\u308a\u305f\u3044\u4e8b<\/h2>\n\n\n\n<p>3\u79d2\u6bce\u306b\u73fe\u5728\u6642\u523b\u3092\u30d6\u30e9\u30a6\u30b6\u3078\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b9\u30c6\u30fc\u30c8\u51e6\u7406\u306e\u4f8b<\/h2>\n\n\n\n<p>App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>import React from &#39;react&#39;;\n\nfunction App() {\n\n  \/\/ \u73fe\u5728\u6642\u523b\u3092\u8fd4\u5374\u3059\u308b\n  const showClock = () =&gt; {\n    const nowTime = new Date();\n    const nowHour = nowTime.getHours();\n    const nowMin  = nowTime.getMinutes();\n    const nowSec  = nowTime.getSeconds();\n    return &quot;\u73fe\u5728\u6642\u523b\uff1a&quot; + nowHour + &quot;:&quot; + nowMin + &quot;:&quot; + nowSec;\n  };\n\n  \/\/ \u30b9\u30c6\u30fc\u30c8\n  const [val, setVal] = React.useState(showClock());\n\n  \/\/ 3\u79d2\u3054\u3068\u306b\u73fe\u5728\u6642\u523b\u3092\u66f4\u65b0\u3059\u308b\n  setTimeout(() =&gt; {\n    setVal(showClock());\n  }, 3000);\n\n  return (\n    &lt;div&gt;{val}&lt;\/div&gt;\n  );\n}\n\nexport default App;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b9\u30c6\u30fc\u30c8\u306e\u5229\u7528<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u304c\u30b9\u30c6\u30fc\u30c8\u306e\u5229\u7528\u3092\u958b\u59cb\u3057\u3066\u3044\u308b\u7b87\u6240\u306b\u306a\u308a\u307e\u3059\u3002<br>\u30b9\u30c6\u30fc\u30c8\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3059\u308b\u3068\u30b9\u30c6\u30fc\u30c8\u5024\u306e\u521d\u671f\u5024\u3068\u3057\u3066\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306f\u3001\u5f15\u6570\u306b\u73fe\u5728\u6642\u523b(showClock\u95a2\u6570)\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001showClock\u95a2\u6570\u306e\u5b9f\u884c\u7d50\u679c\u304c\u30b9\u30c6\u30fc\u30c8\u5024(val\u5909\u6570)\u306e\u521d\u671f\u5024\u3068\u3057\u3066\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ \u30b9\u30c6\u30fc\u30c8\nconst [val, setVal] = React.useState(showClock());<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u73fe\u5728\u6642\u523b\u306e\u8fd4\u5374<\/h3>\n\n\n\n<p>showClock\u95a2\u6570\u306f\u73fe\u5728\u6642\u523b\u3092\u8fd4\u5374\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>  \/\/ \u73fe\u5728\u6642\u523b\u3092\u8fd4\u5374\u3059\u308b\n  const showClock = () =&gt; {\n    const nowTime = new Date();\n    const nowHour = nowTime.getHours();\n    const nowMin  = nowTime.getMinutes();\n    const nowSec  = nowTime.getSeconds();\n    return &quot;\u73fe\u5728\u6642\u523b\uff1a&quot; + nowHour + &quot;:&quot; + nowMin + &quot;:&quot; + nowSec;\n  };<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b9\u30c6\u30fc\u30c8\u5024\u306e\u66f4\u65b0<\/h3>\n\n\n\n<p>setTimeout\u95a2\u6570\u306e\u4e2d\u3067\u30b9\u30fc\u30c6\u30c8\u5024\u66f4\u65b0\u95a2\u6570\u3067\u3042\u308bsetVal\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u30023\u79d2\u7f6e\u304d\u306bsetVal\u95a2\u6570\u3078\u73fe\u5728\u6642\u523b(showClock\u95a2\u6570)\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>  \/\/ 3\u79d2\u3054\u3068\u306b\u73fe\u5728\u6642\u523b\u3092\u66f4\u65b0\u3059\u308b\n  setTimeout(() =&gt; {\n    setVal(showClock());\n  }, 3000);<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b9\u30c6\u30fc\u30c8\u5024\u306e\u8868\u793a<\/h3>\n\n\n\n<p>\u30b9\u30c6\u30fc\u30c8\u5024\u3067\u3042\u308b val \u3092\u30d6\u30e9\u30a6\u30b6\u3078\u8868\u793a\u3055\u305b\u307e\u3059\u30023\u79d2\u7f6e\u304d\u306bsetVal\u95a2\u6570\u3078\u73fe\u5728\u6642\u523b\u304c\u8a2d\u5b9a\u3055\u308c\u3001\u3053\u308c\u306b\u4f34\u3044 val \u306e\u5024\u3082\u5909\u66f4\u3055\u308c\u308b\u306e\u3067\u30013\u79d2\u7f6e\u304d\u306b\u8868\u793a\u3055\u308c\u308b\u5185\u5bb9\u3082\u5909\u308f\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>  return (\n    &lt;div&gt;{val}&lt;\/div&gt;\n  );<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u7279\u306b\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u307e\u3067\u306f\u56fa\u5b9a\u306e\u6587\u5b57\u3092\u30d6\u30e9\u30a6\u30b6\u3078\u8868\u793a\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":968,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-3485","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3485"}],"version-history":[{"count":13,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3485\/revisions"}],"predecessor-version":[{"id":3566,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3485\/revisions\/3566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/968"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}