{"id":821,"date":"2020-02-05T11:55:37","date_gmt":"2020-02-05T11:55:37","guid":{"rendered":"https:\/\/www.webhozz.com\/code\/?p=821"},"modified":"2020-02-07T10:21:54","modified_gmt":"2020-02-07T10:21:54","slug":"props-react-js","status":"publish","type":"post","link":"https:\/\/www.webhozz.com\/code\/props-react-js\/","title":{"rendered":"Props React JS"},"content":{"rendered":"\n<p>Props adalah\nargumen yang diteruskan ke komponen Rect JS.<\/p>\n\n\n\n<p>Props\nditeruskan ke komponen melalui atribut HTML.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Props React JS<\/strong><\/h5>\n\n\n\n<p>Fungsi Props React JS dalam\nargumen seperti dalam JavaScript&nbsp;<em>dan<\/em>&nbsp;atribut dalam HTML.<\/p>\n\n\n\n<p>Untuk mengirim Props ke dalam\nkomponen, gunakan sintaks yang sama dengan atribut <\/p>\n\n\n\n<p>HTML:<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n\n<p>Tambahkan atribut &#8220;brand&#8221; ke elemen Car:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nconst myelement = &lt;Car brand=&quot;Ford&quot; \/&gt;;\n<\/pre><\/div>\n\n\n<p>Komponen menerima argumen sebagai objek&nbsp;<code>props<\/code>:<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n\n<p>Gunakan atribut brand\ndalam komponen:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Car extends React.Component {\n  render() {\n    return &lt;h2&gt;I am a {this.props.brand}!&lt;\/h1&gt;;\n  }\n}\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>Melalui Data<\/strong><\/h5>\n\n\n\n<p>Props juga dapat dengan &nbsp;cara mengirimkan data dari satu komponen ke\nkomponen lainnya, sebagai parameter.<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n\n<p>Kirim properti &#8220;brand&#8221; dari komponen Garage ke komponen Car:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Car extends React.Component {\n  render() {\n    return &lt;h2&gt;I am a {this.props.brand}!&lt;\/h2&gt;;\n  }\n}\n\nclass Garage extends React.Component {\n  render() {\n    return (\n      &lt;div&gt;\n      &lt;h1&gt;Who lives in my garage?&lt;\/h1&gt;\n      &lt;Car brand=&quot;Ford&quot; \/&gt;\n      &lt;\/div&gt;\n    );\n  }\n}\n\nReactDOM.render(&lt;Garage \/&gt;, document.getElementById('root'));\n<\/pre><\/div>\n\n\n<p>Jika kamu memiliki variabel untuk\ndikirim, dan bukan string seperti pada contoh di atas, kamu cukup memasukkan\nnama variabel ke dalam kurung keriting:<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n\n<p>Buat variabel bernama\n&#8220;carname&#8221; dan kirim ke komponen Car:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Car extends React.Component {\n  render() {\n    return &lt;h2&gt;I am a {this.props.brand}!&lt;\/h2&gt;;\n  }\n}\n\nclass Garage extends React.Component {\n  render() {\n    const carname = &quot;Ford&quot;;\n    return (\n      &lt;div&gt;\n      &lt;h1&gt;Who lives in my garage?&lt;\/h1&gt;\n      &lt;Car brand={carname} \/&gt;\n      &lt;\/div&gt;\n    );\n  }\n}\n\nReactDOM.render(&lt;Garage \/&gt;, document.getElementById('root'));\n<\/pre><\/div>\n\n\n<p>Atau jika itu adalah objek:<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n\n<p>Buat objek bernama\n&#8220;carinfo&#8221; dan kirim ke komponen Car:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Car extends React.Component {\n  render() {\n    return &amp;lt;h2&gt;I am a {this.props.brand.model}!&amp;lt;\/h2&gt;;\n  }\n}\n\nclass Garage extends React.Component {\n  render() {\n    const carinfo = {name: &quot;Ford&quot;, model: &quot;Mustang&quot;};\n    return (\n      &amp;lt;div&gt;\n      &amp;lt;h1&gt;Who lives in my garage?&amp;lt;\/h1&gt;\n      &amp;lt;Car brand={carinfo} \/&gt;\n      &amp;lt;\/div&gt;\n    );\n  }\n}\n\nReactDOM.render(&amp;lt;Garage \/&gt;, document.getElementById('root'));\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\"><strong>Props dalam\nKonstruktor<\/strong><\/h5>\n\n\n\n<p>Jika komponen kamu memiliki fungsi\nkonstruktor, Props &nbsp;harus selalu\nditeruskan ke konstruktor dan juga ke React.Component melalui&nbsp;metode<code> super()<\/code>.<\/p>\n\n\n\n<p><strong>Contoh<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Car extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n  render() {\n    return &amp;lt;h2&gt;I am a Car!&amp;lt;\/h2&gt;;\n  }\n}\n\nReactDOM.render(&amp;lt;Car model=&quot;Mustang&quot;\/&gt;, document.getElementById('root'));\n<\/pre><\/div>\n\n\n<p><strong>Catatan:<\/strong>&nbsp;Props\nReact hanya untuk dibaca!&nbsp;kamu akan mengalami error jika kamu mencoba\nmengubah nilainya.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Props adalah argumen yang diteruskan ke komponen Rect JS. Props diteruskan ke komponen melalui atribut HTML. Props React JS Fungsi Props React JS dalam argumen<\/p>\n","protected":false},"author":1,"featured_media":775,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-reactjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Belajar Props React JS - WebHozz Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhozz.com\/code\/props-react-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Belajar Props React JS - WebHozz Code\" \/>\n<meta property=\"og:description\" content=\"Props adalah argumen yang diteruskan ke komponen Rect JS. Props diteruskan ke komponen melalui atribut HTML. Props React JS Fungsi Props React JS dalam argumen\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhozz.com\/code\/props-react-js\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHozz Code\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-05T11:55:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-07T10:21:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/04c781607b26b4f4f052684571acc0c6\"},\"headline\":\"Props React JS\",\"datePublished\":\"2020-02-05T11:55:37+00:00\",\"dateModified\":\"2020-02-07T10:21:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/\"},\"wordCount\":187,\"image\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/logo-reactjs.jpg\",\"articleSection\":[\"ReactJS\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/\",\"name\":\"Belajar Props React JS - WebHozz Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/logo-reactjs.jpg\",\"datePublished\":\"2020-02-05T11:55:37+00:00\",\"dateModified\":\"2020-02-07T10:21:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/04c781607b26b4f4f052684571acc0c6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/logo-reactjs.jpg\",\"contentUrl\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/logo-reactjs.jpg\",\"width\":750,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/props-react-js\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Props React JS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\",\"name\":\"WebHozz Code\",\"description\":\"Tutorial Web &amp; Pemrograman Indonesia\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/04c781607b26b4f4f052684571acc0c6\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Belajar Props React JS - WebHozz Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhozz.com\/code\/props-react-js\/","og_locale":"en_US","og_type":"article","og_title":"Belajar Props React JS - WebHozz Code","og_description":"Props adalah argumen yang diteruskan ke komponen Rect JS. Props diteruskan ke komponen melalui atribut HTML. Props React JS Fungsi Props React JS dalam argumen","og_url":"https:\/\/www.webhozz.com\/code\/props-react-js\/","og_site_name":"WebHozz Code","article_published_time":"2020-02-05T11:55:37+00:00","article_modified_time":"2020-02-07T10:21:54+00:00","og_image":[{"width":750,"height":400,"url":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#article","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/"},"author":{"name":"admin","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/04c781607b26b4f4f052684571acc0c6"},"headline":"Props React JS","datePublished":"2020-02-05T11:55:37+00:00","dateModified":"2020-02-07T10:21:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/"},"wordCount":187,"image":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg","articleSection":["ReactJS"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/","url":"https:\/\/www.webhozz.com\/code\/props-react-js\/","name":"Belajar Props React JS - WebHozz Code","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#primaryimage"},"image":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg","datePublished":"2020-02-05T11:55:37+00:00","dateModified":"2020-02-07T10:21:54+00:00","author":{"@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/04c781607b26b4f4f052684571acc0c6"},"breadcrumb":{"@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhozz.com\/code\/props-react-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#primaryimage","url":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg","contentUrl":"https:\/\/www.webhozz.com\/code\/wp-content\/uploads\/2020\/01\/logo-reactjs.jpg","width":750,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhozz.com\/code\/props-react-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhozz.com\/code\/"},{"@type":"ListItem","position":2,"name":"Props React JS"}]},{"@type":"WebSite","@id":"https:\/\/www.webhozz.com\/code\/#website","url":"https:\/\/www.webhozz.com\/code\/","name":"WebHozz Code","description":"Tutorial Web &amp; Pemrograman Indonesia","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhozz.com\/code\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/04c781607b26b4f4f052684571acc0c6","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bff35e4083f3870e2f911c4437e788147d340f274268d361dd7e1cf20bebb156?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.webhozz.com\/code\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/comments?post=821"}],"version-history":[{"count":1,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/821\/revisions"}],"predecessor-version":[{"id":822,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/821\/revisions\/822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media\/775"}],"wp:attachment":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media?parent=821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/categories?post=821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/tags?post=821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}