<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[React JS Intro]]></title><description><![CDATA[<p dir="auto"></p><section class="align-center"><img src="/assets/uploads/files/1545989079639-reac-resized.png" alt="0_1545988991425_reac.png" class=" img-responsive img-markdown" /></section><p></p>
<p dir="auto"><strong>What is React JS</strong></p>
<ul>
<li>React is a JavaScript library for building user interfaces.</li>
</ul>
<p dir="auto"><strong>React Components</strong></p>
<ul>
<li>
<p dir="auto">Everything in React is a component, and these usually take the form of JavaScript classes. You create a component by extending upon the React-Component class.<br />
Eg:</p>
<pre><code>class MyComponent extends React.Component {
    render() {
        return &lt;h1&gt;Hello world!&lt;/h1&gt;;
    }
}
</code></pre>
</li>
<li>
<p dir="auto">You then define the methods for the component. In our example, we only have  <code>render()</code> method.</p>
</li>
<li>
<p dir="auto">Inside <code>render()</code> you’ll return a description of what you want React to draw on the page. In the case above, we simply want it to display an h1 tag with the text Hello world! inside it.</p>
</li>
</ul>
<p dir="auto"><strong>Props and States</strong></p>
<ul>
<li>
<p dir="auto">There are two types of data in React: props and state.</p>
</li>
<li>
<p dir="auto">The key difference is that state is private and can be changed from within the component itself. Props are external, and not controlled by the component itself. It’s passed down from components higher up the hierarchy, who also control the data.</p>
</li>
<li>
<p dir="auto">The difference between the two is a bit tricky to understand in the beginning, so don’t worry if you find it a bit confusing. i'll show you how to work with props and states in the next tutorial.</p>
</li>
</ul>
<p dir="auto"><strong>Setting Up</strong></p>
<ul>
<li>
<p dir="auto">First create a <code>.html</code> file</p>
</li>
<li>
<p dir="auto">Then import react like below</p>
<pre><code>&lt;!-- ... other HTML ... --&gt;

  &lt;!-- Load React. --&gt;
  &lt;!-- Note: when deploying, replace "development.js" with "production.min.js". --&gt;
  &lt;script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin&gt;    &lt;/script&gt;
  &lt;script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin&gt;&lt;/script&gt;

&lt;/body&gt;
</code></pre>
</li>
</ul>
<p dir="auto"><strong>Add a DOM Container to the HTML</strong></p>
<ul>
<li>
<p dir="auto">Add an empty <code>&lt;div&gt;</code> tag to mark the spot where you want to display something with React. For example:</p>
<pre><code>&lt;!-- ... existing HTML ... --&gt;

&lt;div id="save_button_container"&gt;&lt;/div&gt;

&lt;!-- ... existing HTML ... --&gt;
</code></pre>
</li>
<li>
<p dir="auto">We gave this <code>&lt;div&gt;</code> a unique id HTML attribute. This will allow us to find it from the JavaScript code later and display a React component inside of it.</p>
</li>
</ul>
<p dir="auto"><strong>Creating a React Component</strong></p>
<ul>
<li>
<p dir="auto">Create a file called <code>save_button.js</code> next to your HTML page.</p>
</li>
<li>
<p dir="auto">Add below code to <code>save_button.js</code> file</p>
<pre><code>'use strict';

const e = React.createElement;

class SaveButton extends React.Component {
  constructor(props) {
    super(props);
    this.state = { saved: false };
  }

  render() {
    if (this.state.liked) {
      return 'You saved this.';
    }

    return e(
      'button',
      { onClick: () =&gt; this.setState({ saved: true }) },
      'Save'
    );
  }
}

//These two lines of code find the &lt;div&gt; we added to our HTML in the last step, and then display our “Save” button React component inside of it.
const domContainer = document.querySelector('#save_button_container');
ReactDOM.render(e(SaveButton), domContainer);
</code></pre>
</li>
</ul>
<p dir="auto"><strong>Loading our React Component</strong></p>
<pre><code>&lt;!-- ... other HTML ... --&gt;

  &lt;!-- Load our React component. --&gt;
  &lt;script src="save_button.js"&gt;&lt;/script&gt;

&lt;/body&gt;
</code></pre>
<ul>
<li>Open the <code>.html</code> file you create using your favourite browser and you will see something like below:</li>
</ul>
<p dir="auto"><img src="/assets/uploads/files/1545988047238-d79088ee-6b1c-4907-a2d8-1bdf0470a236-image-resized.png" alt="0_1545987958832_d79088ee-6b1c-4907-a2d8-1bdf0470a236-image.png" class=" img-responsive img-markdown" /></p>
<p dir="auto"><strong>Full Example</strong></p>
<ul>
<li>
<p dir="auto"><code>index.html</code></p>
<pre><code>&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;React App&lt;/title&gt;
&lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Welcome to my React App&lt;/h1&gt;
        &lt;div id="save_button_container"&gt;&lt;/div&gt;

        &lt;!-- Load React. --&gt;
        &lt;!-- Note: when deploying, replace "development.js" with "production.min.js". --&gt;
        &lt;script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin&gt;&lt;/script&gt;
        &lt;script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin&gt;&lt;/script&gt;

        &lt;!-- Load our React component. --&gt;
        &lt;script src="save_button.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
</li>
<li>
<p dir="auto"><code>save_button.js</code></p>
<pre><code>'use strict';
 
const e = React.createElement;
 
class SaveButton extends React.Component {
  constructor(props) {
    super(props);
    this.state = { saved: false };
  }
 
  render() {
    if (this.state.liked) {
      return 'You saved this.';
    }
 
    return e(
      'button',
      { onClick: () =&gt; this.setState({ saved: true }) },
      'Save'
    );
  }
}
 
//These two lines of code find the &lt;div&gt; we added to our HTML in the last step, and then display our “Save” button React component inside of it.
const domContainer = document.querySelector('#save_button_container');
ReactDOM.render(e(SaveButton), domContainer);
</code></pre>
</li>
</ul>
<p dir="auto">Thanks for reading, in the next tutorial i'll talk about</p>
<ul>
<li>Props and States</li>
</ul>
]]></description><link>https://lankadevelopers.lk/topic/59/react-js-intro</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 08:54:35 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/59.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Dec 2018 09:22:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to React JS Intro on Wed, 15 May 2019 04:28:30 GMT]]></title><description><![CDATA[<p dir="auto">Thank you</p>
]]></description><link>https://lankadevelopers.lk/post/1519</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1519</guid><dc:creator><![CDATA[rachitha]]></dc:creator><pubDate>Wed, 15 May 2019 04:28:30 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Mon, 13 May 2019 17:17:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/631">@dileepanipun</a> welcome machn..</p>
]]></description><link>https://lankadevelopers.lk/post/1512</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1512</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Mon, 13 May 2019 17:17:16 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Mon, 13 May 2019 15:42:19 GMT]]></title><description><![CDATA[<p dir="auto">Thanx for this. ✌️</p>
]]></description><link>https://lankadevelopers.lk/post/1511</link><guid isPermaLink="true">https://lankadevelopers.lk/post/1511</guid><dc:creator><![CDATA[dileepanipun]]></dc:creator><pubDate>Mon, 13 May 2019 15:42:19 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Sat, 29 Dec 2018 06:12:54 GMT]]></title><description><![CDATA[<p dir="auto">React &lt;3</p>
]]></description><link>https://lankadevelopers.lk/post/381</link><guid isPermaLink="true">https://lankadevelopers.lk/post/381</guid><dc:creator><![CDATA[isuru mahesh perera]]></dc:creator><pubDate>Sat, 29 Dec 2018 06:12:54 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Fri, 28 Dec 2018 13:30:59 GMT]]></title><description><![CDATA[<p dir="auto">Nice article... thanks bro</p>
]]></description><link>https://lankadevelopers.lk/post/378</link><guid isPermaLink="true">https://lankadevelopers.lk/post/378</guid><dc:creator><![CDATA[fern]]></dc:creator><pubDate>Fri, 28 Dec 2018 13:30:59 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Fri, 28 Dec 2018 11:13:23 GMT]]></title><description><![CDATA[<p dir="auto">Good Explanation, react is the future of  web frontend</p>
]]></description><link>https://lankadevelopers.lk/post/377</link><guid isPermaLink="true">https://lankadevelopers.lk/post/377</guid><dc:creator><![CDATA[lkdev]]></dc:creator><pubDate>Fri, 28 Dec 2018 11:13:23 GMT</pubDate></item><item><title><![CDATA[Reply to React JS Intro on Fri, 28 Dec 2018 09:26:13 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a></p>
]]></description><link>https://lankadevelopers.lk/post/375</link><guid isPermaLink="true">https://lankadevelopers.lk/post/375</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Fri, 28 Dec 2018 09:26:13 GMT</pubDate></item></channel></rss>