<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sai Tanmayee Chervi</title>
    <description>The latest articles on DEV Community by Sai Tanmayee Chervi (@saichervi).</description>
    <link>https://dev.to/saichervi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F860446%2F0d8ea64a-3068-4402-add9-654ab0971967.png</url>
      <title>DEV Community: Sai Tanmayee Chervi</title>
      <link>https://dev.to/saichervi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saichervi"/>
    <language>en</language>
    <item>
      <title>Can we call root.render() inside setInterval()?</title>
      <dc:creator>Sai Tanmayee Chervi</dc:creator>
      <pubDate>Tue, 10 May 2022 13:57:20 +0000</pubDate>
      <link>https://dev.to/saichervi/why-doesnt-calling-rootrender-inside-setinterval-work-4ga5</link>
      <guid>https://dev.to/saichervi/why-doesnt-calling-rootrender-inside-setinterval-work-4ga5</guid>
      <description>&lt;p&gt;Why doesn't the below code work?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const root = ReactDOM.createRoot(document.getElementById('root'));

function Clock() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello, world!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;It is {new Date().toLocaleTimeString()}.&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
   );
}

setInterval( root.render(&amp;lt;Clock /&amp;gt;), 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But why does wrapping the root.render() in a tick method like below work?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const root = ReactDOM.createRoot(document.getElementById('root'));

function Clock(props) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello, world!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;It is {props.date.toLocaleTimeString()}.&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function tick() {
  root.render(&amp;lt;Clock date={new Date()} /&amp;gt;);
}

setInterval(tick, 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Forgive me! I'm a beginner :)&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>help</category>
    </item>
  </channel>
</rss>
