{"id":4650,"date":"2023-08-26T12:50:26","date_gmt":"2023-08-26T12:50:26","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=4650"},"modified":"2023-08-26T12:54:52","modified_gmt":"2023-08-26T12:54:52","slug":"next-js%e3%81%a8react%e3%81%ae%e9%81%95%e3%81%84%e3%81%a8%e3%81%af","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/next-js%e3%81%a8react%e3%81%ae%e9%81%95%e3%81%84%e3%81%a8%e3%81%af\/","title":{"rendered":"Next.js\u3068React\u306e\u9055\u3044\u3068\u306f"},"content":{"rendered":"<p data-sourcepos=\"3:1-3:153\">React\u3068Next.js\u306f\u3001\u4e21\u8005\u3068\u3082\u73fe\u4ee3\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u958b\u767a\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u4eba\u6c17\u306e\u3042\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u30fb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002<\/p>\n<p data-sourcepos=\"6:1-6:171\">\u3057\u304b\u3057\u3001<!--more-->\u305d\u308c\u305e\u308c\u306e\u76ee\u7684\u3068\u6a5f\u80fd\u306f\u7570\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u305d\u306e\u9055\u3044\u306b\u3064\u3044\u3066\u3001\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u306e\u4f8b\u3092\u4ea4\u3048\u3066\u3054\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<h2 data-sourcepos=\"8:1-8:24\">1. \u57fa\u672c\u7684\u306a\u9055\u3044<\/h2>\n<p data-sourcepos=\"10:1-10:110\">\ud83d\udc49 \u30dd\u30a4\u30f3\u30c8: React\u306f<strong>\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong>\u3001Next.js\u306fReact\u306e\u305f\u3081\u306e<strong>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af<\/strong>\u3067\u3059\u3002<\/p>\n<p data-sourcepos=\"12:1-12:115\">React\u306fFacebook\u304c\u958b\u767a\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<p data-sourcepos=\"14:1-14:156\">\u4e00\u65b9\u3001Next.js\u306fReact\u3092\u30d9\u30fc\u30b9\u306b\u3057\u305f\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3084\u9759\u7684\u30b5\u30a4\u30c8\u751f\u6210\u3092\u5bb9\u6613\u306b\u3059\u308b\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/\/ React\u306e\u57fa\u672c\u7684\u306a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\r\nfunction App() {\r\n  return &lt;div&gt;Hello React!&lt;\/div&gt;;\r\n}\r\n\r\n\/\/ Next.js\u306e\u57fa\u672c\u7684\u306a\u30da\u30fc\u30b8\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\r\nfunction HomePage() {\r\n  return &lt;div&gt;Hello Next.js!&lt;\/div&gt;;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2 data-sourcepos=\"28:1-28:39\">2. \u958b\u767a\u74b0\u5883\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h2>\n<p data-sourcepos=\"30:1-30:80\">\ud83d\udc49 \u30dd\u30a4\u30f3\u30c8: Next.js\u306f\u958b\u767a\u74b0\u5883\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u304c\u7c21\u5358\u3067\u3059\u3002<\/p>\n<p data-sourcepos=\"32:1-32:104\">React\u30a2\u30d7\u30ea\u3092\u30bc\u30ed\u304b\u3089\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u5834\u5408\u3001Webpack\u3084Babel\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p data-sourcepos=\"35:1-35:139\">\u4e00\u65b9\u3001Next.js\u3067\u306f\u3053\u308c\u3089\u306e\u8a2d\u5b9a\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u7d44\u307f\u8fbc\u307e\u308c\u3066\u304a\u308a\u3001\u958b\u767a\u30b5\u30fc\u30d0\u30fc\u3092\u3059\u3050\u306b\u8d77\u52d5\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\"># React\u30a2\u30d7\u30ea\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\r\nnpx create-react-app my-app\r\n\r\n# Next.js\u30a2\u30d7\u30ea\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\r\nnpx create-next-app my-next-app\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2 data-sourcepos=\"45:1-45:24\">3. \u30eb\u30fc\u30c6\u30a3\u30f3\u30b0<\/h2>\n<p data-sourcepos=\"47:1-47:102\">\ud83d\udc49 \u30dd\u30a4\u30f3\u30c8: Next.js\u306f<strong>\u30d5\u30a1\u30a4\u30eb\u30d9\u30fc\u30b9\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0<\/strong>\u3092\u63a1\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p data-sourcepos=\"49:1-49:188\">React\u81ea\u4f53\u306b\u306f\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u6a5f\u80fd\u306f\u542b\u307e\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001\u4f8b\u3048\u3070<code>react-router-dom<\/code>\u306a\u3069\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p data-sourcepos=\"52:1-52:140\">\u4e00\u65b9\u3001Next.js\u3067\u306f<code>pages<\/code>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u69cb\u9020\u306b\u57fa\u3065\u3044\u3066\u81ea\u52d5\u7684\u306b\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/\/ React\u3067\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u4f8b\r\n&lt;Route path=\"\/about\" component={About} \/&gt;\r\n\r\n\/\/ Next.js\u3067\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\r\n\/\/ pages\/about.js\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3060\u3051\u3067\u3001\/about\u30eb\u30fc\u30c8\u304c\u81ea\u52d5\u7684\u306b\u751f\u6210\u3055\u308c\u308b\u3002\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2 data-sourcepos=\"62:1-62:79\">4. \u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0(SSR)\u3068\u9759\u7684\u30b5\u30a4\u30c8\u751f\u6210(SSG)<\/h2>\n<p data-sourcepos=\"64:1-64:75\">\ud83d\udc49 \u30dd\u30a4\u30f3\u30c8: Next.js\u306f<strong>SSR\u3068SSG\u3092\u7c21\u5358\u306b\u5b9f\u88c5<\/strong>\u3067\u304d\u307e\u3059\u3002<\/p>\n<p data-sourcepos=\"66:1-66:227\">React\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0(CSR)\u304c\u4e3b\u3067\u3059\u304c\u3001Next.js\u3067\u306fSSR\u3084SSG\u3092\u5bb9\u6613\u306b\u53d6\u308a\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001SEO\u5bfe\u7b56\u3084\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a\u306b\u8ca2\u732e\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/\/ Next.js\u3067\u306eSSR\u4f8b\r\nexport async function getServerSideProps() {\r\n  \/\/ \u30c7\u30fc\u30bf\u306e\u30d5\u30a7\u30c3\u30c1\u3084DB\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306a\u3069\r\n  return { props: { data: fetchedData } };\r\n}\r\n\r\n\/\/ Next.js\u3067\u306eSSG\u4f8b\r\nexport async function getStaticProps() {\r\n  \/\/ \u30c7\u30fc\u30bf\u306e\u30d5\u30a7\u30c3\u30c1\u3084DB\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306a\u3069\r\n  return { props: { data: fetchedData } };\r\n}\r\n<\/pre>\n<p>\u307e\u3068\u3081\u308b\u3068\u3001React\u3068Next.js\u306f\u3001\u305d\u308c\u305e\u308c\u7570\u306a\u308b\u76ee\u7684\u3068\u7279\u5fb4\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002\u3069\u3061\u3089\u3092\u9078\u629e\u3059\u308b\u304b\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8981\u4ef6\u3084\u76ee\u7684\u306b\u5fdc\u3058\u3066\u9078\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>React\u3068Next.js\u306f\u3001\u4e21\u8005\u3068\u3082\u73fe\u4ee3\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u958b\u767a\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u4eba\u6c17\u306e\u3042\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u30fb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002 \u3057\u304b\u3057\u3001<\/p>\n","protected":false},"author":1,"featured_media":4376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[508,12],"tags":[286,458,695],"newstopic":[653,578],"class_list":{"0":"post-4650","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"category-web-development","9":"tag-next-js","10":"tag-react-js","11":"tag-reactnext-js","12":"newstopic-next-js","13":"newstopic-react"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=4650"}],"version-history":[{"count":6,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4650\/revisions"}],"predecessor-version":[{"id":4656,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/4650\/revisions\/4656"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/4376"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=4650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=4650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=4650"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=4650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}