(window.webpackJsonp=window.webpackJsonp||[]).push([[159],{485:function(t,s,a){"use strict";a.r(s);var n=a(3),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"案例演示"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#案例演示"}},[t._v("#")]),t._v(" 案例演示")]),t._v(" "),s("p",[t._v("本节内容根据官方文档的 "),s("a",{attrs:{href:"https://zh-hans.reactjs.org/tutorial/tutorial.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("教程"),s("OutboundLink")],1),t._v(" 编写。")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://codepen.io/gaearon/pen/gWWZgR?editors=0010",target:"_blank",rel:"noopener noreferrer"}},[t._v("在线demo"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"案例代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#案例代码"}},[t._v("#")]),t._v(" 案例代码")]),t._v(" "),s("div",{staticClass:"language-jsx line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-jsx"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" React "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'react'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" ReactDOM "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'react-dom'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'./index.css'")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 正方形格子 (没有state时可以使用函数组件)")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Square")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("props")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// return 返回一个React元素")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//