<?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: Yazan Aabed</title>
    <description>The latest articles on DEV Community by Yazan Aabed (@yazanaabed).</description>
    <link>https://dev.to/yazanaabed</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%2F139590%2F8d1f8908-691d-4d21-a41a-1396e5c9a322.jpg</url>
      <title>DEV Community: Yazan Aabed</title>
      <link>https://dev.to/yazanaabed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yazanaabed"/>
    <language>en</language>
    <item>
      <title>React-testing-library have fantastic testing</title>
      <dc:creator>Yazan Aabed</dc:creator>
      <pubDate>Fri, 20 Jul 2018 20:08:18 +0000</pubDate>
      <link>https://dev.to/yazanaabed/react-testing-library-have-fantastic-testing-48f3</link>
      <guid>https://dev.to/yazanaabed/react-testing-library-have-fantastic-testing-48f3</guid>
      <description>&lt;p&gt;&lt;em&gt;I did not know what is testing, and why people check their implementation. So, I decided to learn more about it, and the favour is for&lt;/em&gt; &lt;a href="https://medium.com/u/db72389e89d8"&gt;&lt;em&gt;Kent C. Dodds&lt;/em&gt;&lt;/a&gt; &lt;em&gt;testing courses.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Check my other article about testing, and what I know about testing for more information&lt;/em&gt; &lt;a href="https://medium.com/yazanaabed/what-i-know-about-testing-in-javascript-6657d2188c3a"&gt;&lt;em&gt;“Make JavaScript Testing Work for You”&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BL1Mg4X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2ANZHHyLwNW_0dS3HE" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BL1Mg4X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2ANZHHyLwNW_0dS3HE" alt="" width="880" height="586"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@siniz?utm_source=medium&amp;amp;utm_medium=referral"&gt;Siniz Kim&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/YazanAabed"&gt;twitter&lt;/a&gt; or check my latest articles on &lt;a href="https://www.yaabed.com/"&gt;my site yaabed.com&lt;/a&gt;. Also, I have my publication at &lt;a href="https://medium.com/yazanaabed"&gt;medium blog.yaabed.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A library is something that contains things you do it every day like jQuery includes an implementation for dealing with DOM element efficiently.&lt;/p&gt;

&lt;p&gt;Testing is something cool in programming phases, I don’t know why people hate it. It gives you the confidence that your code never broke after a while, typically when the application going big every day, and new people joining your team.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Your test must make your code better. — &lt;/em&gt;&lt;a href="https://medium.com/u/db72389e89d8"&gt;&lt;em&gt;Kent C. Dodds&lt;/em&gt;&lt;/a&gt; &lt;a href="https://frontendmasters.com/courses/testing-react/"&gt;&lt;em&gt;workshop&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, what is react-testing-library? And why &lt;a href="https://medium.com/u/db72389e89d8"&gt;Kent C. Dodds&lt;/a&gt; built it for us? Let’s start by defining what is react-testing-library and how to use it.&lt;/p&gt;

&lt;p&gt;React-testing-library is a small library change a way you deal with a DOM element, I mean instead of searching for a div element as a result from your component, this library gives you the ability to search for things using the final result, like what user sees in his browser, users see texts, not divs.&lt;/p&gt;

&lt;p&gt;When you search for a text, this will give you the confidence that you are not testing the implementation details for your component. For example, if you have a header or navbar for your application and when the user logged in your header component need to change the text from login to be a username, react-testing-library make it easy for us.&lt;/p&gt;

&lt;p&gt;What is the benefit of 100% testing coverage and the user for your application can’t even be logged in? For me, I didn’t get the chance to work with a team that tests their code. I hope this will be soon, I learn testing with my self and watch courses about this topic.&lt;/p&gt;

&lt;p&gt;Check this example how things broke when you change the selector for your testing element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QAkHs1wI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AuV-Ndde361wFQNQEI8813g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QAkHs1wI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AuV-Ndde361wFQNQEI8813g.png" alt="" width="880" height="608"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HSLLOm-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A6Ozt07wyOekoI2_hjvosXQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HSLLOm-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A6Ozt07wyOekoI2_hjvosXQ.png" alt="" width="880" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If by mistake or by the requirement one of your team member change the class selector from “login-button” to something else, this will break your testing and need to change the test every time the selector changed.&lt;/p&gt;

&lt;p&gt;To solve this problem, we can use react-testing-library to solve the selector problem by searching for login text inside the component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--35eIOxC4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Aizrhxvkl5CdidapdOuV7Hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--35eIOxC4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Aizrhxvkl5CdidapdOuV7Hw.png" alt="" width="880" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For me, the second example is more comfortable to understand that you are searching for a login button and you want to click it. In that example, you will simulate the user behaviour.&lt;/p&gt;

&lt;p&gt;The entry point is the render method from react-testing-library, it returns various utils, and you can use it with your tests.&lt;/p&gt;

&lt;p&gt;There are also multiple entry points you can use it, check the &lt;a href="https://github.com/kentcdodds/react-testing-library"&gt;Github&lt;/a&gt; account for this library for more information.&lt;/p&gt;

&lt;p&gt;In the above example, the render method returns getByText util, and there are more and more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/kentcdodds/react-testing-library/blob/fd2df8d18652786a95bce34741180137f9d2cef2/README.md#container"&gt;container&lt;/a&gt;: This returns a regular DOM element that used to contain the rendered component.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/kentcdodds/react-testing-library/blob/fd2df8d18652786a95bce34741180137f9d2cef2/README.md#getbylabeltexttext-textmatch-options-selector-string---htmlelement"&gt;getByLabelText&lt;/a&gt;: This will be used to get a form element that its label is the input text.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/kentcdodds/react-testing-library/blob/fd2df8d18652786a95bce34741180137f9d2cef2/README.md#getbytestidtext-textmatch-htmlelement"&gt;getByTestId&lt;/a&gt;: This will get an element by its data-testid attribute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another util is the &lt;a href="https://github.com/kentcdodds/react-testing-library/blob/fd2df8d18652786a95bce34741180137f9d2cef2/README.md#wait"&gt;wait&lt;/a&gt; method allows you to wait for a time, for example an API call. I suggest you give it a try by your self it is fantastic.&lt;/p&gt;

&lt;p&gt;Like if my login button trigger a login API to make sure that this is the right user, this change will break our test because the getByText will through an exception that it is not finding the element. So to solve this we will use the wait method from react-testing-library, it will wait until the logout text appears on the page.&lt;/p&gt;

&lt;p&gt;But, for an API call, please use something called mock with jest, I gave an introduction to it in &lt;a href="https://medium.com/yazanaabed/what-i-know-about-testing-in-javascript-6657d2188c3a"&gt;my other article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, don’t forget to clear your tests before each test, you can use abeforeEach method in jest or you can use react-testing-library util called a cleanup-after-each. You just need to import it from the library like this: import “react-testing-library/cleanup-after-each”;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Vvmr_YJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Ac26CycmIpP8vIAZMMZfyzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Vvmr_YJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Ac26CycmIpP8vIAZMMZfyzA.png" alt="" width="880" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--65LHFViP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AeWcRFeoK0ZocwdUliKkrPQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--65LHFViP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AeWcRFeoK0ZocwdUliKkrPQ.png" alt="" width="880" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Testing is essential don’t make it a secondary item for your application development phases. It will give you the confidence that your application is still working every release.&lt;/p&gt;

&lt;p&gt;In my present team, we build things using AngularJS, and we don’t have the confidence that we can remove items or change class name even we can’t delete a file that we are sure that this file doesn’t used anywhere. My advice for any new team to set testing as standards for their team.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Don’t afraid of using this library, give it a try and read more about it. I think it will be an advantage for testing react application using jest. I heard people all the time afraid of these things and said it would add complexity. However, I am working now with a big team, and they don’t consider stuff for the long-term, this will goes wrong when your application goes significantly, after a while this will reduce the confidence of our front-end project, and this gives a miserable feeling every day.&lt;/p&gt;

&lt;p&gt;In the end, It is incredible how people work every day to help other people make their coding life easy. I hope I will be one of them soon. Thank you for everyone give something new for the community.&lt;/p&gt;

&lt;p&gt;Check this code I have created it on my codesandbox:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/7bfe9b585703dc21e58ca4049d1edbc3/href"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/7bfe9b585703dc21e58ca4049d1edbc3/href"&gt;https://medium.com/media/7bfe9b585703dc21e58ca4049d1edbc3/href&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>testing</category>
      <category>learning</category>
    </item>
    <item>
      <title>Five Ways to Advanced React Patterns</title>
      <dc:creator>Yazan Aabed</dc:creator>
      <pubDate>Tue, 03 Jul 2018 20:07:35 +0000</pubDate>
      <link>https://dev.to/yazanaabed/five-ways-to-advanced-react-patterns-2bai</link>
      <guid>https://dev.to/yazanaabed/five-ways-to-advanced-react-patterns-2bai</guid>
      <description>&lt;p&gt;&lt;em&gt;What I have learned after I watch&lt;/em&gt; &lt;a href="https://medium.com/u/db72389e89d8" rel="noopener noreferrer"&gt;&lt;em&gt;Kent C. Dodds&lt;/em&gt;&lt;/a&gt; &lt;em&gt;“Advanced React Patterns” course at&lt;/em&gt; &lt;a href="https://medium.com/u/1b199ed2dfd" rel="noopener noreferrer"&gt;&lt;em&gt;Frontend Masters&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AqatotphqCyOKDuGbDl4Qwg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AqatotphqCyOKDuGbDl4Qwg.jpeg"&gt;&lt;/a&gt;Photo by rawpixel.com from Pexels&lt;/p&gt;

&lt;p&gt;I fall in love with ReactJS and start learning what I can determine. I begin watching courses, write code, read articles. After that, I decided to start writing what I learned from ReactJS community and the expert people out there.&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/YazanAabed" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; or check my latest articles on &lt;a href="https://www.yaabed.com/" rel="noopener noreferrer"&gt;my site yaabed.com&lt;/a&gt;. Also, I have my publication at &lt;a href="https://medium.com/yazanaabed" rel="noopener noreferrer"&gt;medium blog.yaabed.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before continue reading this article I suggest you read my other article about ReactJS “&lt;a href="https://dev.to/yazanaabed/is-learning-reactjs-for-you-gg5-temp-slug-2571611"&gt;What I know about ReactJS!&lt;/a&gt;” if you are a beginner with ReactJS, or watch &lt;a href="https://medium.com/u/db72389e89d8" rel="noopener noreferrer"&gt;Kent C. Dodds&lt;/a&gt; &lt;a href="https://egghead.io/courses/the-beginner-s-guide-to-react" rel="noopener noreferrer"&gt;beginner course at&lt;/a&gt; “&lt;a href="https://egghead.io/" rel="noopener noreferrer"&gt;https://egghead.io/&lt;/a&gt;”.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let’s get started learning advance ReactJS together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React programming patterns are used to simplify large React applications and make your team experience easier, this helps your team to build separate components and share logic between them.&lt;/p&gt;

&lt;p&gt;After reading this article, you will learn more about modern React patterns like Compound Components, Render Props, Prop Getters, Controller Props, Context API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advanced React Patterns
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Software_design_pattern" rel="noopener noreferrer"&gt;Software Patterns&lt;/a&gt; give you the ability to make your code more reusable, general.&lt;/p&gt;

&lt;h4&gt;
  
  
  Compound Components
&lt;/h4&gt;

&lt;p&gt;A compound component is a way to write elements inside each other, but the primary condition is the inner components doesn’t work without their primary parent.&lt;/p&gt;

&lt;p&gt;We can define it also as sharing the same state shared the same parent and shared parent state.&lt;/p&gt;

&lt;p&gt;One of my favourite example the tabs component I have built it when I start learning ReactJS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/f039cea09c73e99b79a33ed9cb95d168/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/f039cea09c73e99b79a33ed9cb95d168/href" rel="noopener noreferrer"&gt;https://medium.com/media/f039cea09c73e99b79a33ed9cb95d168/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AQ2GT9jT73stIP74NZRamwQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AQ2GT9jT73stIP74NZRamwQ.png"&gt;&lt;/a&gt;Compound components example.&lt;/p&gt;

&lt;p&gt;If you need to share things from the parent container to its children, you can use React.Children provide utilities for dealing with this.props.children.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2Afmah_c-NhYabdzVTK0DG4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2Afmah_c-NhYabdzVTK0DG4g.png"&gt;&lt;/a&gt;Share props from parent component.&lt;/p&gt;

&lt;p&gt;But, this solution not flexible enough for compound components, because when you change the order for your parts or wrap them inside another element, they will not now have access to the props, because of the map function loop through the first level inside the parent component.&lt;/p&gt;

&lt;p&gt;To solve the above problem, we need another way to share state between components without broken if the user for your plugin changes the way he represents the element. We can use Context API to share state between components.&lt;/p&gt;

&lt;p&gt;The first element to use Context API is called Provider, and the provider element is the wrapper parent for elements that shared the same state. Then we have the Consumer, that every component inside the provider can use it to get or retrieve the values from the provider.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0NHlhyfcpTAycVx8wlAqFg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0NHlhyfcpTAycVx8wlAqFg.png"&gt;&lt;/a&gt;How to create context element with React.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AFlBUvuRhGLeGMDMyE1L-ng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AFlBUvuRhGLeGMDMyE1L-ng.png"&gt;&lt;/a&gt;This is the parent element for every consumer needs to use the parent state.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For the above code, it is not a best practice to set object like this, because every time the render method called it creates a new reference and new object. So people said to put these things inside the component state even the callbacks to avoid re-render every time without need.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AVZzBHA18B3-HWt3ATm63mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AVZzBHA18B3-HWt3ATm63mw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A-l5GOXOQH8f6xskSyHZyvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A-l5GOXOQH8f6xskSyHZyvg.png"&gt;&lt;/a&gt;This is how to use the consumer and retrieve parent state.&lt;/p&gt;

&lt;p&gt;Please note that the consumer children are function passed to the consumer and the consumer gives the state to the children.&lt;/p&gt;

&lt;p&gt;Compound components are useful when my user for the component, does not need to care about the implementation details. For example, we have state in the parent component check if tabs clicked or not.&lt;/p&gt;

&lt;p&gt;I recommend you try it by your self to learn more about how to share things between components, &lt;a href="https://codesandbox.io/s/6vx9026q1z" rel="noopener noreferrer"&gt;here&lt;/a&gt; is a simple project to start work. Try to make it use the Context API instead of React.Children.&lt;/p&gt;

&lt;h4&gt;
  
  
  Render Props
&lt;/h4&gt;

&lt;p&gt;This technique use props, that’s why it is called render props. You pass a function as a render method that returns ReactJS element and used to render things.&lt;/p&gt;

&lt;p&gt;The convention is to name it to render props, but no need to call it like that, some people also use children props as function. But, any properties you pass as a function to render things from another place this called as “Render props”.&lt;/p&gt;

&lt;p&gt;I mean by props is that your component inputs. Let me show you an example in the next code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AtLfVv8PJbyUK4xbPUP3Xxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AtLfVv8PJbyUK4xbPUP3Xxg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look at the end of the component. It is a children component but instead of using it as {this.props.children} we use it as a function and pass to it the arguments we need to make the user for our component return for us the components he needs. Look at the next code how to use this component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A46mK7NGtKwcEr_PaUAKgew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A46mK7NGtKwcEr_PaUAKgew.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice right? Try it by your self and change one of your props to a function and pass for it whatever you need to move. This trick allows you to create sharing things without even use the Context API.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://medium.com/u/db72389e89d8" rel="noopener noreferrer"&gt;Kent C. Dodds&lt;/a&gt; “Advanced React Patterns” course at &lt;a href="https://medium.com/u/1b199ed2dfd" rel="noopener noreferrer"&gt;Frontend Masters&lt;/a&gt; he gives some excellent tips to use when using render props. I recommend also watch “&lt;a href="https://egghead.io/courses/advanced-react-component-patterns" rel="noopener noreferrer"&gt;Advanced React Component Patterns&lt;/a&gt;” course in &lt;a href="https://egghead.io/" rel="noopener noreferrer"&gt;egghead.io&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AuC4aQiIt7QtOs9QT" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AuC4aQiIt7QtOs9QT"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@ludemeula?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Ludemeula Fernandes&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Controlled Components
&lt;/h4&gt;

&lt;p&gt;Controlled is means that you are the one who responsible for changing the state for something by your self. One of the famous example your form inputs, when you pass a value props to your “input” things change.&lt;/p&gt;

&lt;p&gt;Now when the user starts typing, you have to pass onChange event for your input to make sure you change it in your state. If you give a value attribute without changing the state, the user input will never reflect the actual text he enters.&lt;/p&gt;

&lt;p&gt;That’s why it is called controlled, you control the changes and pass it another time to your input.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/u/db72389e89d8" rel="noopener noreferrer"&gt;Kent C. Dodds&lt;/a&gt; also gives an excellent example, like when the user clicks something more than four times, and I need to give him a message and stop him from typing, this can’t happen if I am not the one who writes the component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASh3Tw5IydO9u7INNJYlNIw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASh3Tw5IydO9u7INNJYlNIw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2At2ysMbK_K4l7q_VYXy1seA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2At2ysMbK_K4l7q_VYXy1seA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For my tabs component, I have changed that the active tab is now taking from the props and I am not the one who controls it. I trigger an event that the user clicks my component and you change the active tabs by your self.&lt;/p&gt;

&lt;h4&gt;
  
  
  State Reducer
&lt;/h4&gt;

&lt;p&gt;A reducer is a simple function takes an input and return output without any changing on your application state. This type of services called a pure function.&lt;/p&gt;

&lt;p&gt;A state reducer used to give your component a function to generate new state depends on the value returned from the reducer. For example on my tabs component user pass a prop called stateReducer as a function, and inside tabs component, we call this function on any change for the state to happen inside the tabs component and assign it as a new state.&lt;/p&gt;

&lt;p&gt;This kind of patterns is the same as controlling a component by your props, but this time the component owner send you the old state and the changes and give you the decision to change the inner state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AuFhpzHRxE-jbgL1W1yQkog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AuFhpzHRxE-jbgL1W1yQkog.png"&gt;&lt;/a&gt;&lt;a href="https://codesandbox.io/s/w7kv2080vw" rel="noopener noreferrer"&gt;State reducer example&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ADVC1x3Gq5tMS4tu2m4E4YA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ADVC1x3Gq5tMS4tu2m4E4YA.png"&gt;&lt;/a&gt;Pass state reducer to component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AAqHvOBNUS-x9qtUeJYie-Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AAqHvOBNUS-x9qtUeJYie-Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final code to trigger your state with the values returns from the state reducer. You can say that this somehow like reducers used in redux.&lt;/p&gt;

&lt;h4&gt;
  
  
  Higher-Order Components
&lt;/h4&gt;

&lt;p&gt;Higher-Order component is a function that takes a ReactJS component and does some logic on top of it and returns new application component. This pattern is used in most of the library out there for ReactJS. For example, redux use this to merge props from store top level to any component.&lt;/p&gt;

&lt;p&gt;Also, I have used this with &lt;a href="https://medium.com/u/9d99f1b2974b" rel="noopener noreferrer"&gt;Material-UI&lt;/a&gt;, to pass classes object to your component, or extends the style for their application components. This way of writing your application component with &lt;a href="https://medium.com/u/9d99f1b2974b" rel="noopener noreferrer"&gt;Material-UI&lt;/a&gt; called withStyle HOC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ADFUZawHb_VWkrAV6vm4nzQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ADFUZawHb_VWkrAV6vm4nzQ.png"&gt;&lt;/a&gt;Sidebar example for show user name or login button&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;After a while, I discovered that write about what you learn makes your information more strong. Give these pattern a try, they make your components unique, especially if you are one of the people love the open source community. These patterns make your components more reusable, more people to use it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>patterns</category>
      <category>development</category>
    </item>
    <item>
      <title>Is Learning ReactJS For You?</title>
      <dc:creator>Yazan Aabed</dc:creator>
      <pubDate>Mon, 04 Jun 2018 22:58:03 +0000</pubDate>
      <link>https://dev.to/yazanaabed/is-learning-reactjs-for-you-lng</link>
      <guid>https://dev.to/yazanaabed/is-learning-reactjs-for-you-lng</guid>
      <description>&lt;p&gt;&lt;a href="https://reactjs.org/"&gt;&lt;em&gt;ReactJS&lt;/em&gt;&lt;/a&gt; &lt;em&gt;is an impressive library to create things and build a user interface. Team form Facebook made it for us.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MxC0OC4S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2AI2LVy4WMsn6Umd4R" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MxC0OC4S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2AI2LVy4WMsn6Umd4R" alt="" width="880" height="586"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@frsphoto?utm_source=medium&amp;amp;utm_medium=referral"&gt;Felix Russell-Saw&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/YazanAabed"&gt;twitter&lt;/a&gt; or check my latest articles on &lt;a href="https://www.yaabed.com/"&gt;my site yaabed.com&lt;/a&gt;. Also, I have my publication at &lt;a href="https://medium.com/yazanaabed"&gt;medium blog.yaabed.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before I learn to React, I don’t know why people love working with it that much, and companies ask about it every frontend interview. Moreover, people told me that writing HTML in a separate file is the best practice for your project, now React team write the template on another way inside your JavaScript file.&lt;/p&gt;

&lt;p&gt;There is too many questions come to your mind before you learn React. However, I decided to start learning React. After I learn React, I understand why we write the template in that way. It shows to me that React is the future for the web development, it changes how I think about developing web applications.&lt;/p&gt;

&lt;p&gt;Liquid error: internal&lt;/p&gt;

&lt;p&gt;You can learn to React by yourself. I recommend every front-end engineer to learn it. React extends your knowledge, especially how you think about your design, your components, your user interface, your application architecture.&lt;/p&gt;

&lt;p&gt;In this article, I give an overview what I know about ReactJS and what I learn about it. I hope you enjoy reading this.&lt;/p&gt;

&lt;p&gt;Watch this video to know five things about React. — &lt;a href="https://medium.com/u/a3a8af6addc1"&gt;Dan Abramov&lt;/a&gt; &amp;amp; &lt;a href="https://medium.com/u/d4377b6d15d2"&gt;Burke H✪lland&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/3DCeoCpTIAI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Before I start to discuss the building items for any React project, I recommend people to watch these courses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://egghead.io/courses/the-beginner-s-guide-to-react"&gt;The Beginner’s Guide to React&lt;/a&gt; — &lt;a href="https://medium.com/u/db72389e89d8"&gt;Kent C. Dodds&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactforbeginners.com/"&gt;React For Beginners&lt;/a&gt; — &lt;a href="https://medium.com/u/86a55cd7983b"&gt;Wes Bos&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://frontendmasters.com/courses/react/"&gt;Complete Intro to React&lt;/a&gt; — &lt;a href="https://medium.com/u/69ba9847d710"&gt;Brian Holt&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I discuss the elements of any React application and where is the starting point for any application with React. Also, I give an overview steps to build any React application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N0z21uyq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AvV2mYuwX7lcZsncydIlvvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N0z21uyq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AvV2mYuwX7lcZsncydIlvvw.png" alt="" width="880" height="331"&gt;&lt;/a&gt;This is my first React application 🔥✨&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need to import React writing React application.&lt;/li&gt;
&lt;li&gt;We need to import the render function from react-dom.&lt;/li&gt;
&lt;li&gt;We need to define where to render our application using render method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Root Element
&lt;/h3&gt;

&lt;p&gt;Any React application need a root container to start from it. render function give us the ability to render any React component to HTML DOM. The most thing I like about this render function is that you can test your application easy and render your application to fake DOM element with your testing library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7dKCUN9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AeXmNdsutdSN2npW2PpOzXg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7dKCUN9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AeXmNdsutdSN2npW2PpOzXg.png" alt="" width="880" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;The component is a View in MVC. You divide your application as you see the application design. For example Header, SideBar, Button.&lt;/p&gt;

&lt;p&gt;Also, a component could be a page or a container like Home, Login, Dashboard.&lt;/p&gt;

&lt;p&gt;React application divided into multiple React components, and every component contains a render method which is the entry point for your component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gowGHAbh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AZNLMhhwo0huzxojc1-0gtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gowGHAbh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AZNLMhhwo0huzxojc1-0gtg.png" alt="" width="880" height="353"&gt;&lt;/a&gt;Paragraph component&lt;/p&gt;

&lt;p&gt;React library use the render method to know what to render when you use the Paragraph component. And this is how we use our components inside our project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SKy4Mmak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AWufN_zS7DKCe-xHK0dMhbA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SKy4Mmak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AWufN_zS7DKCe-xHK0dMhbA.png" alt="" width="880" height="443"&gt;&lt;/a&gt;Use Paragraph component&lt;/p&gt;

&lt;p&gt;I recommend you try to build component by yourself or try to divide any design you got in your job to component and think why you divide it like that.&lt;/p&gt;

&lt;p&gt;Make sure to understand this quote before you divide your application into components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“A component should, ideally, only be responsible for one piece of functionality.” —&lt;a href="https://www.fullstackreact.com/"&gt; Fullstack React&lt;/a&gt;, &lt;a href="https://medium.com/u/fac5e491c445"&gt;Sophia Shoemaker&lt;/a&gt; &amp;amp; &lt;a href="https://medium.com/u/6538666cdb34"&gt;Nate Murray&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--OKA2Lr3y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/705003311083229184/qTBCIxpk_normal.jpg" alt="Programming Wisdom profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Programming Wisdom
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="mentioned-user" href="https://dev.to/codewisdom"&gt;@codewisdom&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      "The central enemy of reliability is complexity." - Geer et al.
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      16:29 PM - 03 Jun 2018
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1003312607418347521" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1003312607418347521" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1003312607418347521" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  Components contain two primary weapons
&lt;/h3&gt;

&lt;p&gt;You can use these two weapons to make your component more reusable and more flexible.&lt;/p&gt;

&lt;h4&gt;
  
  
  Props
&lt;/h4&gt;

&lt;p&gt;Props are the inputs for your component, owned by the component parent and passed from there. Any component use props more reusable than other components hide its values inside it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yKqFfloG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AR4ZiZ7yoeIjAvQk6Z7ygxA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yKqFfloG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AR4ZiZ7yoeIjAvQk6Z7ygxA.png" alt="" width="880" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Props are the primary weapon for reusability because if we define the blogs array inside the Blogs component, can’t use in other places in the app or with other blogs values other places in our application needs.&lt;/p&gt;

&lt;p&gt;These type of component that works only with props called stateless components. Every time you give the same component same input, it renders the same output or the same DOM.&lt;/p&gt;

&lt;p&gt;Things to check when start working with props:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/typechecking-with-proptypes.html"&gt;Type checking With PropTypes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/components-and-props.html"&gt;Components and Props&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0"&gt;Presentational and Container Components&lt;/a&gt; — &lt;a href="https://medium.com/u/a3a8af6addc1"&gt;Dan Abramov&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  State
&lt;/h4&gt;

&lt;p&gt;The component itself owns a state, a state can be modified using the component itself, or can be initialized using the props from outside.&lt;/p&gt;

&lt;p&gt;The one place the state initialized is inside the constructor, after that you need to use a setState method from React.Component object to modify the state for your component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xZgl81_V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Ac84rUbTht2PcCLMMZwytAQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xZgl81_V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Ac84rUbTht2PcCLMMZwytAQ.png" alt="" width="880" height="1151"&gt;&lt;/a&gt;Login component contains its state and manages its state.&lt;/p&gt;

&lt;p&gt;These two weapons could be your enemy if you don’t use them wisely, mainly when you use the setState method in wrong places and trigger re-render without any need. So, please think twice before you design your components and what to use. If the component doesn’t take a state and get the values from outside, it is more reusable this called stateless components if the component manages its state this called stateful components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O-1dLK5v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2Ab3SyKELKooLlcupz" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O-1dLK5v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2Ab3SyKELKooLlcupz" alt="" width="880" height="1163"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@ay_leon?utm_source=medium&amp;amp;utm_medium=referral"&gt;Leon Rojas&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Virtual DOM
&lt;/h3&gt;

&lt;p&gt;React team modify things for us it doesn’t allow us to work with the browser DOM is built for us something called the virtual dom. React team take care of the changes with the DOM in an optimized way.&lt;/p&gt;

&lt;h4&gt;
  
  
  The problem with manual change for DOM:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Hard to keep track for every change.&lt;/li&gt;
&lt;li&gt;It is slow for some cases to change the DOM using the JavaScript.&lt;/li&gt;
&lt;li&gt;The Facebook team gave a talk and said that JavaScript is very fast but modify the DOM is too slow.&lt;/li&gt;
&lt;li&gt;React team said that your component has to return the HTML you wish to see and react team take the responsibility from you to update the view for you.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main reason that React team doesn’t take the state from the DOM because the DOM is too slow, so they decide to make the state change from their side.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why would we want to do that our component’s state from its DOM representation? There are two good reasons:&lt;/p&gt;

&lt;p&gt;1) It’s faster, 2) It’s less complicated.— &lt;a href="https://jrsinclair.com/articles/2018/react-redux-javascript-architecture/"&gt;REACT, REDUX AND JAVASCRIPT ARCHITECTURE&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/NVWrdSz2Q5c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps to build react project
&lt;/h3&gt;

&lt;p&gt;First thing for React application is to divide your UI into components and make sure that every component do one thing and responsible for one thing.&lt;/p&gt;

&lt;p&gt;When you build the application components, try to build the components with static values and make sure it works fine without any server or any BE.&lt;/p&gt;

&lt;p&gt;Think which component of your application contains a state. Add static state for your component and try to change it. Add events trigger to move data around the component. After this add the server to your components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Timeline for React component
&lt;/h3&gt;

&lt;p&gt;You can read more about React life cycle &lt;a href="https://medium.com/@baphemot/understanding-reactjs-component-life-cycle-823a640b3e8d"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The constructor for the component is run, and the initial state now did.&lt;/li&gt;
&lt;li&gt;Then render method is called then call render for children to make sure to render the component.&lt;/li&gt;
&lt;li&gt;The initial render now run.&lt;/li&gt;
&lt;li&gt;The componentDidMount lifecycle is triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Routing with React
&lt;/h3&gt;

&lt;p&gt;The user request the index.html page and then the server doesn’t care what the user does.&lt;/p&gt;

&lt;p&gt;When you build the user router at the browser, this called a single page application.&lt;/p&gt;

&lt;p&gt;React router: The app wrap with router provider when the route changed all component listen for the change and check if the path for is it renders else return null.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Finally, I recommend every frontend engineer to give ReactJS a try; it is a fantastic library to build amazing applications. Don’t be afraid of these new things you can do it. Try to build things by yourself. Here is an &lt;a href="https://medium.com/hackteam/5-examples-of-react-applications-build-on-open-source-media-apis-c5b9880d922d"&gt;article&lt;/a&gt; for ideas to learn to React using open source media APIS.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>react</category>
      <category>development</category>
    </item>
  </channel>
</rss>
