1\u3001\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n
\r\nfunction HelloMessage(props) {\r\n return <h1>Hello World!<\/h1>;\r\n}<\/pre>\n\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 ES6 class \u6765\u5b9a\u4e49\u4e00\u4e2a\u7ec4\u4ef6:<\/p>\n
\r\nclass Welcome extends React.Component {\r\n render() {\r\n return <h1>Hello World!<\/h1>;\r\n }\r\n}<\/pre>\n2\u3001const element = <HelloMessage \/> \u4e3a\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u7ec4\u4ef6\u3002<\/p>\n
\u6ce8\u610f\uff0c\u539f\u751f HTML \u5143\u7d20\u540d\u4ee5\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u800c\u81ea\u5b9a\u4e49\u7684 React \u7c7b\u540d\u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u6bd4\u5982 HelloMessage \u4e0d\u80fd\u5199\u6210 helloMessage\u3002\u9664\u6b64\u4e4b\u5916\u8fd8\u9700\u8981\u6ce8\u610f\u7ec4\u4ef6\u7c7b\u53ea\u80fd\u5305\u542b\u4e00\u4e2a\u9876\u5c42\u6807\u7b7e\uff0c\u5426\u5219\u4e5f\u4f1a\u62a5\u9519\u3002<\/p>\n
\u5982\u679c\u6211\u4eec\u9700\u8981\u5411\u7ec4\u4ef6\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 this.props \u5bf9\u8c61,\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/p>\n
React \u5b9e\u4f8b<\/p>\n
\r\nfunction HelloMessage(props) {\r\n return <h1>Hello {props.name}!<\/h1>;\r\n}\r\n \r\nconst element = <HelloMessage name=\"Runoob\"\/>;\r\n \r\nReactDOM.render(\r\n element,\r\n document.getElementById('example')\r\n);\r\n<\/pre>\n\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d name \u5c5e\u6027\u901a\u8fc7 props.name \u6765\u83b7\u53d6\u3002
\n\u6ce8\u610f\uff0c\u5728\u6dfb\u52a0\u5c5e\u6027\u65f6\uff0c class \u5c5e\u6027\u9700\u8981\u5199\u6210 className \uff0cfor \u5c5e\u6027\u9700\u8981\u5199\u6210 htmlFor \uff0c\u8fd9\u662f\u56e0\u4e3a class \u548c for \u662f JavaScript \u7684\u4fdd\u7559\u5b57\u3002<\/p>\n
\u590d\u5408\u7ec4\u4ef6<\/strong><\/div>\n\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u591a\u4e2a\u7ec4\u4ef6\u6765\u5408\u6210\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u5373\u628a\u7ec4\u4ef6\u7684\u4e0d\u540c\u529f\u80fd\u70b9\u8fdb\u884c\u5206\u79bb\u3002
\n\u4ee5\u4e0b\u5b9e\u4f8b\u6211\u4eec\u5b9e\u73b0\u4e86\u8f93\u51fa\u7f51\u7ad9\u540d\u5b57\u548c\u7f51\u5740\u7684\u7ec4\u4ef6\uff1a<\/p>\n
React \u5b9e\u4f8b<\/p>\n
\r\nfunction Name(props) {\r\n return <h1>\u7f51\u7ad9\u540d\u79f0\uff1a{props.name}<\/h1>;\r\n}\r\nfunction Url(props) {\r\n return <h1>\u7f51\u7ad9\u5730\u5740\uff1a{props.url}<\/h1>;\r\n}\r\nfunction Nickname(props) {\r\n return <h1>\u7f51\u7ad9\u5c0f\u540d\uff1a{props.nickname}<\/h1>;\r\n}\r\nfunction App() {\r\n return (\r\n <div>\r\n <Name name=\"Linux\u5c31\u8be5\u8fd9\u4e48\u5b66\" \/>\r\n <Url url=\"http:\/\/lrxjmw.cn\" \/>\r\n <Nickname nickname=\"Runoob\" \/>\r\n <\/div>\r\n );\r\n}\r\n \r\nReactDOM.render(\r\n <App \/>,\r\n document.getElementById('example')\r\n);<\/pre>\n\u5b9e\u4f8b\u4e2d App \u7ec4\u4ef6\u4f7f\u7528\u4e86 Name\u3001Url \u548c Nickname \u7ec4\u4ef6\u6765\u8f93\u51fa\u5bf9\u5e94\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u672c\u7ae0\u8282\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528\u7ec4\u4ef6\u4f7f\u5f97\u6211\u4eec\u7684\u5e94\u7528\u66f4\u5bb9\u6613\u6765\u7ba1\u7406\u3002 \u63a5\u4e0b\u6765\u6211\u4eec\u5c01\u88c5\u4e00\u4e2a\u8f93\u51fa “Hello World\uff01” […]<\/p>\n","protected":false},"author":1470,"featured_media":207359,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-207522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=207522"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522\/revisions"}],"predecessor-version":[{"id":207525,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207522\/revisions\/207525"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/207359"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=207522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=207522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=207522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}