{"id":13,"date":"2023-08-26T02:12:06","date_gmt":"2023-08-25T17:12:06","guid":{"rendered":"https:\/\/randd.lib-arc.com\/?p=13"},"modified":"2023-08-26T02:12:06","modified_gmt":"2023-08-25T17:12:06","slug":"firestore%e3%81%8b%e3%82%89%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%ef%bc%91%e4%bb%b6%e5%8f%96%e5%be%97%e3%81%97%e3%81%a6react%e3%81%a7%e8%a1%a8%e7%a4%ba%e3%81%99%e3%82%8b%e7%b0%a1%e5%8d%98%e3%81%aa","status":"publish","type":"post","link":"https:\/\/randd.lib-arc.com\/?p=13","title":{"rendered":"Firestore\u304b\u3089\u30c7\u30fc\u30bf\u3092\uff11\u4ef6\u53d6\u5f97\u3057\u3066React\u3067\u8868\u793a\u3059\u308b\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, {useState,useEffect} from \"react\";\r\nimport * as ReactDOM from \"react-dom\/client\";\r\nimport { initializeApp } from \"firebase\/app\";\r\nimport { getFirestore,collection, getDoc,doc } from \"firebase\/firestore\";\r\n\r\nconst firebaseConfig = {\r\n  \/\/firebase\u304b\u3089\u30b3\u30d4\u30fc\r\n};\r\n\r\n\/\/ Initialize Firebase\r\nconst app = initializeApp(firebaseConfig);\r\nconst db = getFirestore(app);\r\n\r\n\r\nconst root = ReactDOM.createRoot(\r\n  document.getElementById('root') as HTMLElement);\r\nroot.render(\r\n  &lt;React.StrictMode>\r\n    &lt;App \/>\r\n  &lt;\/React.StrictMode>\r\n);\r\n\r\nfunction App(){\r\n  const &#91;name,setName] = useState(\"\");\r\n  useEffect(() => {\r\n    const docRef = doc(db,\"test\",\"yGhMBQE4ZETTzA5Y9CkC\");\r\n    getDoc(docRef).then((docSnap) => {\r\n    console.log(docSnap.data());\r\n    setName(docSnap.data().name)})\r\n  })\r\n  return(\r\n    &lt;div>\r\n      &lt;h1>Firestore&lt;\/h1>\r\n      \r\n      &lt;h2>{name}&lt;\/h2>\r\n    &lt;\/div>\r\n  );\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13","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\/13","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=13"}],"version-history":[{"count":2,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randd.lib-arc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}