{"componentChunkName":"component---src-templates-blog-post-js","path":"/react/web-components-with-react/","result":{"data":{"site":{"siteMetadata":{"title":"Recipes Collection","author":"Internet Community"}},"markdownRemark":{"id":"a07edc15-0948-5aaa-96c3-9f885b670406","html":"<ul>\n<li><a href=\"#introduction\">Introduction</a></li>\n<li><a href=\"#using-web-components-in-react\">Using Web Components in React</a></li>\n</ul>\n<h1 id=\"introduction\"><a href=\"#introduction\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introduction</h1>\n<ul>\n<li>Web Components provide strong encapsulation for reusable components, while React provides a declarative library that keeps the DOM in sync with your data. </li>\n<li>As a developer, you are free to use React in your Web Components, or to use Web Components in React, or both.</li>\n</ul>\n<h1 id=\"using-web-components-in-react\"><a href=\"#using-web-components-in-react\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Using Web Components in React</h1>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">HelloMessage</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>x-search</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>x-search</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">!</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>A <code class=\"language-text\">video</code> Web Component might expose <code class=\"language-text\">play()</code> and <code class=\"language-text\">pause()</code> functions. To access the imperative APIs of a Web Component, you will need to use a ref to interact with the DOM node directly. </li>\n<li>If you are using third-party Web Components, the best solution is to write a React component that behaves as a wrapper for your Web Component.</li>\n<li>Events emitted by a Web Component may not properly propagate through a React render tree. You will need to manually attach event handlers to handle these events within your React components.</li>\n</ul>","timeToRead":1,"frontmatter":{"title":"Web Components with React","date":"April 23, 2022","spoiler":"Following are some notes collected through internet"},"fields":{"slug":"/react/web-components-with-react/","langKey":"en"}}},"pageContext":{"slug":"/react/web-components-with-react/","previous":{"fields":{"slug":"/kubernetes/helm/","langKey":"en","directoryName":"helm","maybeAbsoluteLinks":[]},"frontmatter":{"title":"Helm"}},"next":{"fields":{"slug":"/react/transitions/","langKey":"en","directoryName":"transitions","maybeAbsoluteLinks":[]},"frontmatter":{"title":"Transitions"}},"translations":[],"translatedLinks":[]}}}