{"id":5,"date":"2023-08-13T22:34:27","date_gmt":"2023-08-13T13:34:27","guid":{"rendered":"https:\/\/randd.lib-arc.com\/?p=5"},"modified":"2023-08-13T22:34:57","modified_gmt":"2023-08-13T13:34:57","slug":"react%e3%82%92%e5%8b%95%e3%81%8b%e3%81%99%e7%b0%a1%e5%8d%98%e3%81%aa%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab","status":"publish","type":"post","link":"https:\/\/randd.lib-arc.com\/?p=5","title":{"rendered":"React\u3092\u52d5\u304b\u3059\u7c21\u5358\u306a\u30b5\u30f3\u30d7\u30eb"},"content":{"rendered":"\n<pre class=\"wp-block-code has-base-color has-contrast-background-color has-text-color has-background\"><code>import React, {useReducer} from \"react\";\nimport * as ReactDOM from \"react-dom\/client\";\n\nconst initialState = 0;\n\nconst reducerFunc = (countState: number,action: string) =&gt; {\n  switch (action){\n    case 'up':\n      return countState + 1;\n    case 'down':\n      return countState - 1;\n    default:\n      return countState;\n  }\n}\n\nconst root = ReactDOM.createRoot(\n  document.getElementById('root') as HTMLElement);\nroot.render(\n  &lt;React.StrictMode&gt;\n    &lt;App \/&gt;\n  &lt;\/React.StrictMode&gt;\n);\n\nfunction App(){\n  const &#91;count,dispatch] = useReducer(reducerFunc,initialState);\n  return(\n    &lt;div&gt;\n      &lt;h1&gt;\u30ab\u30a6\u30f3\u30c8\u30a2\u30c3\u30d7&lt;\/h1&gt;\n      &lt;button onClick={()=&gt;dispatch('up')}&gt;UP&lt;\/button&gt;\n      &lt;button onClick={()=&gt;dispatch('down')}&gt;down&lt;\/button&gt;\n      &lt;h2&gt;{count}&lt;\/h2&gt;\n    &lt;\/div&gt;\n  );\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"280\" height=\"201\" src=\"https:\/\/randd.lib-arc.com\/wp-content\/uploads\/2023\/08\/image.png\" alt=\"\" class=\"has-border-color has-tertiary-border-color wp-image-8\" style=\"border-width:2px\"\/><figcaption class=\"wp-element-caption\">\u8868\u793a\u753b\u9762\u30b5\u30f3\u30d7\u30eb<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5"}],"version-history":[{"count":3,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions\/10"}],"wp:attachment":[{"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}