<?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: miral-zymr</title>
    <description>The latest articles on DEV Community by miral-zymr (@miralkumbhani).</description>
    <link>https://dev.to/miralkumbhani</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%2F110760%2Fe1361247-682b-4d1f-8d62-c43b5404adee.png</url>
      <title>DEV Community: miral-zymr</title>
      <link>https://dev.to/miralkumbhani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/miralkumbhani"/>
    <language>en</language>
    <item>
      <title>Day Two - Rendering Elements</title>
      <dc:creator>miral-zymr</dc:creator>
      <pubDate>Mon, 22 Jul 2019 06:38:50 +0000</pubDate>
      <link>https://dev.to/miralkumbhani/day-two-rendering-elements-22c9</link>
      <guid>https://dev.to/miralkumbhani/day-two-rendering-elements-22c9</guid>
      <description>&lt;p&gt;In my previous posts, I have written about JSX and few of its concepts. This post will include the rendering of elements in React.&lt;/p&gt;

&lt;p&gt;Elements are the smallest building blocks of React apps. It is the smallest renderable unit in React. These elements can be rendered using the &lt;em&gt;ReactDOM&lt;/em&gt;. React Elements are plain objects which are easy to render. React Elements and Components are two different terms. &lt;/p&gt;

&lt;p&gt;In order to get React elements rendered, they must be enclosed in the div element with id="root" or "app". React elements are &lt;em&gt;immutable&lt;/em&gt; i.e. once an element is created it is impossible to update its children or attribute. Hence, to update the element, its render method is to be called several times. React render is quite efficient by using virtual DOM and efficient differentiating algorithm. The algorithm checks the rendered data and the updated data and only re-renders the data that needs an update, instead of rendering all data.&lt;/p&gt;

&lt;p&gt;In the next post, I'll be writing about Components and Props in react.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactjavascript</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Day One - JSX</title>
      <dc:creator>miral-zymr</dc:creator>
      <pubDate>Wed, 17 Jul 2019 08:53:39 +0000</pubDate>
      <link>https://dev.to/miralkumbhani/day-one-jsx-4n78</link>
      <guid>https://dev.to/miralkumbhani/day-one-jsx-4n78</guid>
      <description>&lt;p&gt;This is my first blog post here and as a developer and learner, I want to keep it simple. This will be a series of React Concepts that I learn throughout. For a pro, this might be something basic, but I'll make sure the newbies find it helpful. This is just a way to keep a record of my learnings and share and get better at this. &lt;/p&gt;

&lt;h2&gt;
  
  
  JSX
&lt;/h2&gt;

&lt;p&gt;JavaScript XML, in short JSX is used to create React Elements. JSX is mainly used to make coding easier, as it uses couples the UI logic and the functional logic at one place. JSX is an alternative to &lt;em&gt;React.createElement&lt;/em&gt;. It allows us to define the React elements using a syntax which is similar to HTML syntax. &lt;/p&gt;

&lt;p&gt;For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;simpleText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;simpleText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The first line is simple JavaScript, defining a variable, simpleText as a string. The second line is JSX, which is creating an element and we can directly render the variable &lt;code&gt;element&lt;/code&gt;, as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After compilation, JSX expressions also become JavaScript function calls and evaluate JavaScript objects. Babel compiles JSX down to &lt;code&gt;React.createElement()&lt;/code&gt; calls. Hence, we can easily use JSX inside &lt;code&gt;if...else&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; loops, assign it to variables, accept it as arguments, and return it as functions. &lt;/p&gt;

&lt;p&gt;We can use curly braces to embed JavaScript expression to an attribute. Another benefit of using JSX is, it prevents injection attacks.&lt;/p&gt;

&lt;p&gt;JSX can be compared to the following syntax:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React.createElement(component, props, ...children)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The first part (component) determines the type of the React element. &lt;br&gt;
Some key points are: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Capitalized type indicates the JSX is referring to a component. 
&lt;code&gt;React.createElement(&amp;lt;Foo /&amp;gt;, document.getElementById('root');&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The dot-Notation can be used to refer a React component if a single module contains several react components.
&lt;code&gt;&amp;lt;MyComponents.DatePicker /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;React library must always be accessible and be in scope in the JSX code.
&lt;code&gt;import React from 'react;&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;User-defined components must be capitalized.
&lt;code&gt;&amp;lt;Hello toWhat="World" /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When you want to render a different component based on a prop, or maybe dynamically render components based on specific values or conditions, JSX type can be defined as follows:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Story&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SpecificStory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storyType&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SpecificStory&lt;/span&gt; &lt;span class="nx"&gt;story&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;story&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These are some basics about JSX. For my next topic, I'll be covering some advanced JSX concepts and Rendering Elements.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactjavascript</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
