<?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: Bipin singh</title>
    <description>The latest articles on DEV Community by Bipin singh (@singhbipin2117).</description>
    <link>https://dev.to/singhbipin2117</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%2F418428%2F244702e2-24c9-4d70-9136-b8f373418514.jpeg</url>
      <title>DEV Community: Bipin singh</title>
      <link>https://dev.to/singhbipin2117</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/singhbipin2117"/>
    <language>en</language>
    <item>
      <title>What is state &amp; how to use it in react?</title>
      <dc:creator>Bipin singh</dc:creator>
      <pubDate>Sun, 23 Aug 2020 23:30:03 +0000</pubDate>
      <link>https://dev.to/singhbipin2117/what-is-state-in-how-to-use-it-in-react-2ia</link>
      <guid>https://dev.to/singhbipin2117/what-is-state-in-how-to-use-it-in-react-2ia</guid>
      <description>&lt;p&gt;There are many JavaScript framework and library in JS world and every framework and library has a different way to handle data flow. React has a different way to handle data flow which makes it different compare to other framework and library.&lt;/p&gt;

&lt;p&gt;If we want to share data between component, we can use props in react. Which you can learn and understand from my &lt;a href="https://dev.to/singhbipin2117/what-is-props-how-to-use-it-in-react-4jj7"&gt;previous post&lt;/a&gt;. With props, we can pass data from parent to child component and utilize its value, but we can not alter its value and can not send data back to parent from child component.Because props is a read only object as well as data with props is passed in uni-directional flow.&lt;/p&gt;

&lt;p&gt;But sometimes we also want to utilize data within component itself as well as we also want to alter its value. To achieve this dynamic behaviour we can use state in react.&lt;/p&gt;

&lt;p&gt;Let's begin to understand what is state and how to use it in react.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is state
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;State is a JavaScript object in react which holds dynamic data inside component between different render cycle.&lt;/li&gt;
&lt;li&gt;Unlike props this object is private to component.&lt;/li&gt;
&lt;li&gt;Before react version 16.8 state can only be used within classes. But after 16.8 we can use state in functional component with useState hook. Hooks is all together  is a standalone topic which we will cover in future post. But we will learn how to use useState hook in this post.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's understand how to use state in react with a small project(Create a click counter).&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand state with class based approach.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Let's create a class name App which will extends react component.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L7tvQWeF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3k3wg7jow7r1bpboqga7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L7tvQWeF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3k3wg7jow7r1bpboqga7.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Props in the App class is an object which will hold all the attribute data passed to App component.&lt;br&gt;
In class base component props is passed to constructor function.&lt;br&gt;
To utilize props in the component we must need to call super function and should pass props as argument of it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define state in constructor which will hold an object with key count and its initial value as 0.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u0TSsn5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gg5sqg6lthake77kiiya.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u0TSsn5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gg5sqg6lthake77kiiya.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let's define a render function in class component and whatever render function will return will render inside Dom element&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n3ctH-oA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/raktlbz287sl0a1ih5rl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n3ctH-oA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/raktlbz287sl0a1ih5rl.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a p tag which will hold count variable and wrap count variable with interpolation({}) to render it in Dom. Also add button element which will call increment function on click of button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n5cx18Co--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7c92krpt7zry48ho2co.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n5cx18Co--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7c92krpt7zry48ho2co.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now add increment function inside class and call this.setState function which will increment count variable from its previous value by one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hgnck9FT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0swslbpzc97xaoejyamc.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hgnck9FT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0swslbpzc97xaoejyamc.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is our full code which will increment count value by one and also re render component into Dom every time count value is changed.&lt;/p&gt;

&lt;p&gt;Full code can be viewed over here.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/practical-sky-p152t"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand state with function based approach.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: State can be used in functional component using useState hook.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let's create a function name App and import react and useState hook from react.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xz8AKoeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9col03ja5s2oxbfywkfg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xz8AKoeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9col03ja5s2oxbfywkfg.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define useState hook inside component and pass 0 as it's initial value inside useState argument. 
useState hook will return an array which first value will be initial value of the hook and second value will be function with which we can alter the value of the state variable value returned by useState hook.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7ue0N4cW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f1nvk5h25f5dw3khn434.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7ue0N4cW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f1nvk5h25f5dw3khn434.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Over here we had used destructuring to destructure the returned array value.&lt;br&gt;
 You can read more about destructuring over &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let's return a jsx element from the component and whatever function will return will render inside Dom element&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HJi7zCx2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lqet7os5wrlviz8swews.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HJi7zCx2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lqet7os5wrlviz8swews.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a p tag which will hold count variable and wrap count variable with interpolation({}) to render it in Dom. Also add button element which will call increment function on click of button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ashpCtl0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l3x90dw20ohgfqx7l640.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ashpCtl0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l3x90dw20ohgfqx7l640.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now add increment function inside component and call setCount function which will increment count variable from its previous value by one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W9ksn084--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ghn5446epdxkzgc6jo6b.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W9ksn084--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ghn5446epdxkzgc6jo6b.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is our full code which will increment count value by one and also re render component into Dom every time count value is changed.&lt;/p&gt;

&lt;p&gt;Full code can be viewed over here.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/immutable-monad-u9w18"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;If we want to update the component we can use state in react.&lt;br&gt;
For this we can take two approach either by using class or by using function. &lt;br&gt;
It's totally depends on us which approach we want to take.&lt;/p&gt;

&lt;p&gt;Hope this will be helpful for you.&lt;br&gt;
Keep learning.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is props &amp; how to use it in React?</title>
      <dc:creator>Bipin singh</dc:creator>
      <pubDate>Sun, 16 Aug 2020 18:22:23 +0000</pubDate>
      <link>https://dev.to/singhbipin2117/what-is-props-how-to-use-it-in-react-4jj7</link>
      <guid>https://dev.to/singhbipin2117/what-is-props-how-to-use-it-in-react-4jj7</guid>
      <description>&lt;p&gt;Every javascript framework has a different way of data handling and manipulation. React has a different way to handle and manipulate data flow compare to other javascript frameworks that's why it become's difficult to understand some concept like props, state and so on.&lt;/p&gt;

&lt;p&gt;To understand how props works in react, first we have to understand what is component in react and how it works. So i strongly recommend to refer my post  &lt;a href="https://dev.to/singhbipin2117/how-to-create-simple-component-in-react-ec5"&gt;How to create simple component in React&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is props?
&lt;/h2&gt;

&lt;p&gt;React is javascript component based library which divides ui in a small reusable pieces. In some cases we need to also pass data between component to communicate with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Props&lt;/strong&gt; is a special keyword in React, which stands for properties and is being used for passing data from one component to another.&lt;/p&gt;

&lt;p&gt;Data with props is passed in uni-direction flow(Parent to Child).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Props&lt;/strong&gt; data is read only which means its value can not be changed from child component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's see how props work with an example.
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Define an attribute and its value.&lt;/li&gt;
&lt;li&gt;Pass it to the child component.&lt;/li&gt;
&lt;li&gt;Render the props data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understand how props works by an example.&lt;/p&gt;

&lt;p&gt;First create a parent component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ParentComponent() {
 return (
  &amp;lt;h1&amp;gt;I am parent component&amp;lt;/h1&amp;gt;
  &amp;lt;ChildComponent/&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a child component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ChildComponent() {
 return &amp;lt;p&amp;gt;I am child component&amp;lt;/p&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's call a child component multiple times in parent component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ParentComponent() {
 return (
  &amp;lt;h1&amp;gt;I am parent component&amp;lt;/h1&amp;gt;
  &amp;lt;ChildComponent/&amp;gt;
  &amp;lt;ChildComponent/&amp;gt;
  &amp;lt;ChildComponent/&amp;gt;
  &amp;lt;ChildComponent/&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Output of above code will be.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I am parent component
I am child component
I am child component
I am child component
I am child component
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But our goal is to print dynamic data in output.&lt;/p&gt;

&lt;p&gt;To achieve this we have to pass data from parent component to child using props.&lt;/p&gt;

&lt;p&gt;As we learn before props can be passed as an attribute and its value.&lt;/p&gt;

&lt;p&gt;As we know how we can define an attribute in an image html tag.&lt;br&gt;
&lt;code&gt;&amp;lt;img src="img-name.jpg"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The same way we can define an attribute and assign a value with interpolation {} in a react component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ChildComponent firstAttribute={} secondAttribute={}/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's declare a text attribute and it's value to child component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ChildComponent text={I am first child component}/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The attribute we pass in an component is received as an argument in child component like a javascript function is receiving an argument&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # Javascript function
function multiplication(fistArgument, secondArgument) {
 return fistArgument * secondArgument;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the same way child component is also receiving a props as a argument&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function childComponent(props) {

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Before using props directly first logs it to the console and have a look to its value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(props)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1q2yYszk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xis0jw5elikonzdzd3yo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1q2yYszk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xis0jw5elikonzdzd3yo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see props is an javascript object. In javascript we can access object key with &lt;strong&gt;doc(.)&lt;/strong&gt; notation.&lt;/p&gt;

&lt;p&gt;Let's render props in child component with an interpolation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ChildComponent(props) {
 return &amp;lt;p&amp;gt;{props.text}&amp;lt;/p&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also pass props to other child component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ParentComponent() {
 return (
  &amp;lt;h1&amp;gt;I am parent component&amp;lt;/h1&amp;gt;
  &amp;lt;ChildComponent text={I am a first child component}/&amp;gt;
  &amp;lt;ChildComponent text={I am a second child component}/&amp;gt;
  &amp;lt;ChildComponent text={I am a third child component}/&amp;gt;
  &amp;lt;ChildComponent text={I am a fourth child component}/&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Output will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I am parent component
I am first child component
I am second child component
I am third child component
I am fourth child component
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hope this post will help you understand props in react.&lt;br&gt;
Feel free to left out comment below if you have any question.&lt;/p&gt;

&lt;p&gt;Keep learning.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How to create simple component in React</title>
      <dc:creator>Bipin singh</dc:creator>
      <pubDate>Sat, 15 Aug 2020 13:38:50 +0000</pubDate>
      <link>https://dev.to/singhbipin2117/how-to-create-simple-component-in-react-ec5</link>
      <guid>https://dev.to/singhbipin2117/how-to-create-simple-component-in-react-ec5</guid>
      <description>&lt;p&gt;React is a javascript library which makes it easy to create an awesome ui.&lt;/p&gt;

&lt;p&gt;Component is a basic building block of a every react project. Let's understand how we can create a simple hello world component in react.&lt;/p&gt;

&lt;h3&gt;
  
  
  Component can be created in two ways in react.
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Functional component&lt;/li&gt;
&lt;li&gt;Class component&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's first understand how to create a component using class.&lt;/p&gt;

&lt;h4&gt;
  
  
  Class component
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Every react component start with simple import statement.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import React from react
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We have to create a class and have to extends React.component into it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class HelloWorld extends React.component {

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; First letter of the component in react should be capital letter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have to implement render function to render ui into Dom(document object model).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;render() {
  return &amp;lt;h1&amp;gt;Hello world&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To render a component in dom we have to import &lt;code&gt;react-dom&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ReactDOM from 'react-dom'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Complete code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import React from 'react';
import ReactDOM from 'react-dom';

class HelloWorld extends React.component {
 render() {
  return &amp;lt;h1&amp;gt;Hello world&amp;lt;/h1&amp;gt;;
 }
}
ReactDOM.render(&amp;lt;HelloWorld /&amp;gt;, document.getElementById("root"));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Functional component
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Every react component start with simple import statement.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import React from react
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We have to create a function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function HelloWorld {

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We have to return from the function to render ui into Dom(document object model).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return &amp;lt;h1&amp;gt;Hello world&amp;lt;/h1&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To render a component in dom we have to import &lt;code&gt;react-dom&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ReactDOM from 'react-dom'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Complete code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import React from 'react';
import ReactDOM from 'react-dom';

class HelloWorld {
  return &amp;lt;h1&amp;gt;Hello world&amp;lt;/h1&amp;gt;;
}
ReactDOM.render(&amp;lt;HelloWorld /&amp;gt;, document.getElementById("root"));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hope this will be helpful for all of you.&lt;br&gt;
Keep Learning.&lt;/p&gt;

</description>
      <category>react</category>
      <category>component</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
