<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>react on Rise-</title><link>https://madil.in/tag/react/</link><description>Recent content in react on Rise-</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 09 Feb 2023 12:07:37 +0000</lastBuildDate><atom:link href="https://madil.in/tag/react/index.xml" rel="self" type="application/rss+xml"/><item><title>TIL - React's Auto Escaping</title><link>https://madil.in/til-reacts-auto-escaping/</link><pubDate>Thu, 09 Feb 2023 12:07:37 +0000</pubDate><guid>https://madil.in/til-reacts-auto-escaping/</guid><description>&lt;p&gt;React escapes most of the strings to prevent the possibility of cross-site scripting (XSS) attacks. However, there are certain cases where escaping does not happen by default.&lt;/p&gt;&#10;&lt;p&gt;The API for creating elements looks like this -&lt;/p&gt;&#10;&lt;div class="code-block not-prose group relative my-7" x-data="copy(function () { return this.$root.querySelector('pre').innerText })"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e06c75"&gt;React&lt;/span&gt;.&lt;span style="color:#e06c75"&gt;createElement&lt;/span&gt;(&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e06c75"&gt;type&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; [&lt;span style="color:#e06c75"&gt;props&lt;/span&gt;],&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; [...&lt;span style="color:#e06c75"&gt;children&lt;/span&gt;]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="absolute right-2 top-2 flex items-center gap-2"&gt;&lt;span class="select-none text-xs uppercase tracking-wider text-white/40 transition-opacity group-hover:opacity-0"&gt;javascript&lt;/span&gt;&#10; &lt;button type="button" @click="copy()" data-track="code_copied" data-track-props='{&amp;#34;language&amp;#34;:&amp;#34;javascript&amp;#34;}' class="absolute right-0 flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-xs text-white/80 opacity-0 transition-opacity hover:bg-white/20 focus:opacity-100 group-hover:opacity-100"&gt;&#10; &lt;span x-text="copied ? 'Copied' : 'Copy'"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;When passed a dangerous value to &lt;code&gt;[...children]&lt;/code&gt;, the data will be escaped and not be treated as code or executed in the Javascript context of the current page. This handy feature provides security controls preventing cross-site scripting (XSS) attacks.&lt;/p&gt;</description></item></channel></rss>