<?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: Himanshu Kanojiya</title>
    <description>The latest articles on DEV Community by Himanshu Kanojiya (@himanshukanojiya).</description>
    <link>https://dev.to/himanshukanojiya</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%2F675008%2F3e37e084-b1d4-4cee-a8ce-55d87592a0ce.jpeg</url>
      <title>DEV Community: Himanshu Kanojiya</title>
      <link>https://dev.to/himanshukanojiya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshukanojiya"/>
    <language>en</language>
    <item>
      <title>What is the better testing library for React, Enzyme (from Airbnb) VS React testing library (from Kent C. Dodds)?</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Mon, 21 Mar 2022 16:04:21 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/what-is-the-better-testing-library-for-react-enzyme-from-airbnb-vs-react-testing-library-from-kent-c-dodds-c5e</link>
      <guid>https://dev.to/himanshukanojiya/what-is-the-better-testing-library-for-react-enzyme-from-airbnb-vs-react-testing-library-from-kent-c-dodds-c5e</guid>
      <description>&lt;p&gt;I wish, if I did not ignore this earlier, if I took it seriously, then I was not confused to suggest which library we should use in the React for the project.&lt;/p&gt;

&lt;p&gt;A few weeks ago, I was surfing and posted some posts on Linkedin on which react testing library I should use "React testing library or Enzyme library by Airbnb.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F375o86qz2pgj22acq29u.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F375o86qz2pgj22acq29u.jpg" alt="Research on testing library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I spent a lot of time researching this. I visited so many blogs, did a post on community, and all.&lt;/p&gt;

&lt;p&gt;I have received some replies, but still not convinced at all. Then, I did this: I tried both testing libraries. &lt;/p&gt;

&lt;p&gt;Here are some things I have found during research and using both of them that can help you too:&lt;/p&gt;

&lt;h3&gt;
  
  
  Enzyme:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Focuses on unit testing means it tests components prop &amp;amp; states value, not actual user flow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As it depends on components prop and state for testing, if you perform any changes in the code, then all test cases for that component will break. Still, If user behavior (user flow) is the same, your test cases will not work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can perform isolated testing, depends which rendering method you are using. If using shallow rendering, then will render parent component. If using the mount rendering, then it will load parent to child components to test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As it tests components props &amp;amp; states, finding the bug in code is easy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can access components by using CSS selectors for testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enzyme popularity is decreasing day by day (Not even in top 10). To support this statement here is the survey link: &lt;a href="https://2021.stateofjs.com/en-US/libraries/testing/#testing_others" rel="noopener noreferrer"&gt;Enzyme Trend&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no official adapter (it helps the Enzyme distinguish which React version you are using and which necessary files are required to test files for that react version) for React version 17.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As react version 18 beta announced and there are a lot of changes in React API, I don't think version 18 adapter will be possible as changes in API will require a lot of rework for these: Enzyme Adapters, Enzyme itself, enzyme-adapter-utils, and enzyme-adapter-react-helper.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enzyme depends a lot on React internals, one change in React internal can break the whole Enzyme library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you are not planning to migrate to React version 18,  using Enzyme with an unofficial adapter will be enough. In case you are planning to upgrade, then consider React testing library.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  React testing library:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Popular and comes with React if you install react with npx create-react-app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Popularity is increasing day by day. Source: &lt;a href="https://2021.stateofjs.com/en-US/libraries/testing/#testing_experience_marimekko" rel="noopener noreferrer"&gt;Survey by state of js&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kh7sys8mrehnwa5la6q.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kh7sys8mrehnwa5la6q.png" alt="Survey by state of js"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recommend by React team for testing. Source: &lt;a href="https://reactjs.org/docs/testing.html" rel="noopener noreferrer"&gt;https://reactjs.org/docs/testing.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It focuses on user flow-based testing means it performs testing as a real user interacting with your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It gives you more confidence in your code as it tests the same as real users interacting with your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It depends on the user flow, not on the code, which means if you make any changes in the code, not in user behavior (user flow), then your test cases will not break.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As it tests the same as a user interacting with your app, finding the bug in code can become difficult to find.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By default, it has only one type of rendering for testing, "render" same as mount in Enzyme.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Accessing components is not easy like Enzyme, as it is not using CSS selectors instead, it uses other methods such as findBy, and getBy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you need to wait for an element to appear/disappear or a promise has to resolve first, then using findBy methods along with await will help you a lot. Super Easy, right? Yes, it is&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performing user events are almost the same as Enzyme. The only difference is that, in Enzyme, the user needs to pass the event name as a string, and for that, you need to visit the documentation to find an event, but in React testing library, you don't need to. Just access the internal method like this "userEvent.click". It is a Timesaver for me.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you look in Stack Overflow trends, you will see a lot of progress for the react-testing-library, which means if you are stuck somewhere in testing, then there is a huge community to help you. Source: &lt;a href="https://insights.stackoverflow.com/trends?tags=enzyme%2Creact-testing-library" rel="noopener noreferrer"&gt;React testing library &amp;amp; Enzyme Trends&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua6loc114jffrs8vv1j2.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua6loc114jffrs8vv1j2.PNG" alt="React testing library Vs Enzyme Trend on StackOverflow"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  My views:
&lt;/h3&gt;

&lt;p&gt;I am using both libraries, personally like both libraries. There are still many companies out there using Enzyme as they are more interested in traditional testing. So might be there are some chances that you need to use Enzyme over react-testing-libraries, but it is upto us to share pros &amp;amp; cons for it.&lt;/p&gt;

&lt;p&gt;In the long run, I recommend you to use react-testing-library as it is growing rapidly, can perform testing the same as a user interacting with your app, not going to be deprecated or outdated, and has community support.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Short Note about Functional Programming in JavaScript</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Thu, 05 Aug 2021 10:55:45 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/short-note-about-functional-programming-in-javascript-55am</link>
      <guid>https://dev.to/himanshukanojiya/short-note-about-functional-programming-in-javascript-55am</guid>
      <description>&lt;p&gt;Functional programming is programming paradigms where we take care of multiple things like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Each operation decomposes into multiple functions. For example, a Function should perform one task.&lt;/li&gt;
&lt;li&gt;Function should be pure and will always take input and give an output.&lt;/li&gt;
&lt;li&gt;Side effects operation should be encapsulated into another function that is only responsible to handle/perform side effects and should be not mixed with regular operations.&lt;/li&gt;
&lt;li&gt;Immutability, where the function should not change the global data or passed references of arrays and objects (non-primitive values). Instead, make a copy of that data and use it. Like map, filter, and forEach higher-order function.&lt;/li&gt;
&lt;li&gt;Function composition, where one function output becomes the output of another function. &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React JSX in Depth</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Sat, 31 Jul 2021 09:57:10 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/react-jsx-in-depth-3dhj</link>
      <guid>https://dev.to/himanshukanojiya/react-jsx-in-depth-3dhj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt; Basic knowledge of React&lt;/p&gt;

&lt;p&gt;Did you know in React, it is not required to create a component using only JSX? You can use React createElement function as well for building the Components. &lt;/p&gt;

&lt;p&gt;Then, why do people use it most in their React App? Let's deep dive, and understand more about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JSX in React?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
    &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;Hey, I am Himanshu&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;

)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const hOneHeading = &amp;lt;h1&amp;gt;Hey, I am Himanshu&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0u1vlvb8gp1n7de7iluo.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0u1vlvb8gp1n7de7iluo.gif" alt="confuse"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSX (JavaScript XML) is a syntax extension to JavaScript that gives visual aid to developers by allowing them to write HTML types of codes in JavaScript, and it helps to describe &lt;strong&gt;"what the User Interface should look like and how it should be"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After that, React Engine will convert those JSX into React function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React.createElement(component, props, ...children)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Technical Terms, JSX is syntactic sugar in React that provides React.createElement(component, props, ...children) function after converting from JSX.&lt;/p&gt;

&lt;p&gt;So, Instead of writing long and long React.createElement function to create the UI, React team developed JSX to build UI using something that we are used to, which is HTML.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7adj26ujrq1y83wiefgj.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7adj26ujrq1y83wiefgj.gif" alt="Smart Person"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see the breakdown of the JSX converting process to React.createElement function:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSX Code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 className:"topBarHeading"&amp;gt;I am Himanshu&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;compiles to&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React.createElement("h1",{className:"topBarHeading",
"I am Himanshu"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding Expressions into JSX as we do in template literals:
&lt;/h3&gt;

&lt;p&gt;Well, in the end, JSX is JavaScript too. So, adding expressions in JSX is easy because it uses almost the same syntax approach as we use in template literals. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userName = "Himanshu";
const whoLoggedIn = &amp;lt;h1&amp;gt;{userName}&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the curly braces, you can put almost any valid expressions like variables, inline condition checks, perform functions calls, etc. As we see earlier, after compilation, JSX becomes the regular JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Expressions inside curly braces {} always get evaluated. Also, these curly braces give a signal to React that we are using javascript expressions here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Attributes to JSX elements
&lt;/h3&gt;

&lt;p&gt;In HTML, we can add many attributes to specify more about the tag, like adding a class attribute, id attribute, src attribute, etc. &lt;/p&gt;

&lt;p&gt;In React, we can do the same with JSX elements, but the only difference is that JSX is closer to JavaScript than to HTML, so HTML attributes become camelCase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const element = &amp;lt;div tabIndex = "0"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; As the &lt;strong&gt;"class"&lt;/strong&gt; is a reserved keyword in JavaScript, it becomes &lt;strong&gt;className&lt;/strong&gt;, &lt;strong&gt;"for"&lt;/strong&gt; is reserved for loop, it becomes &lt;strong&gt;htmlFor&lt;/strong&gt;, and some other attributes like &lt;strong&gt;tabindex&lt;/strong&gt; become &lt;strong&gt;tabIndex&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Children elements as we do in HTML
&lt;/h3&gt;

&lt;p&gt;Well, creating nested tags in HTML, we all mostly do in our projects, and in React, we can do the same thing as we do in HTML, so here is the way to do the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sampleComponent(){
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h1&amp;gt;Hey, I am himanshu&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;Taskmaster...A JS Master&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        )
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Did you know the JSX feature in React prevents XSS (Cross-site-Scripting Attack) injections Attacks?
&lt;/h3&gt;

&lt;p&gt;How? What happens under the hood?&lt;br&gt;
Well, by default, React DOM escapes any value before rendering them on the screen, which means that whatever value (can be malicious code) you give in the input field will be converted to a string by JSX. Also, if you display the input on the screen, then those inputs will be shown as it is on-screen in text format unless you specified those explicitly in the code.&lt;/p&gt;

&lt;p&gt;This feature in React makes our React-based app safer from XSS (Cross-Site-Scripting attacks).&lt;/p&gt;
&lt;h3&gt;
  
  
  Specifying React Element type using Name Casing
&lt;/h3&gt;

&lt;p&gt;Whenever you create a custom component in your project, always start your component name with a capital case. It will help the ReactJS engine in several ways like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reason:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Help React Engine to easily distinguish which tag is an HTML tag or custom component. Otherwise, some weird things can happen.&lt;/li&gt;
&lt;li&gt;Help you to spot which is the custom component or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In short, Built-in HTML tags in JSX represent in lowercase, and user-defined custom components represent in Capital Case casing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function exampleOfNameCasing(){
return (
    &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;Himanshu kanojiya&amp;lt;/h1&amp;gt;
        &amp;lt;CustomComponent&amp;gt;I am JS Task Master&amp;lt;/CustomComponent&amp;gt;
    &amp;lt;/div&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Accessing internal components from a module using dot notation:
&lt;/h3&gt;

&lt;p&gt;In many cases in the future, you can have or need to build a single module that exports many React components. Well, wrapping multiple React components in a module is a convenient way to encapsulate all React components, and access them as per need &amp;amp; requirements.&lt;/p&gt;

&lt;p&gt;Let's see how we can do this, and access them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyParentComponents = {
    userName:function(name){
        return &amp;lt;h1&amp;gt;User Name: {name}&amp;lt;/h1&amp;gt;
}

function myApp(){
    return (
        &amp;lt;MyParentComponents.userName name="Himanshu" /&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you have a question like, how the object has been written in JSX format or will it be accessible, will it work as component initialization format? &lt;/p&gt;

&lt;p&gt;Yes, It will work because the userName function can be accessed using dot notation as we access object property in JavaScript. The other fact is that the userName function is React component, so it is valid to do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some don't's while using this:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;As it works like JavaScript objects, never use general expressions to access internal components (MyParentComponents[userName], instead, save it to individual variables first, then use it like below:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function doThis(){
    const componentFromModule = MyParentComponents["userName
"]
    return &amp;lt;MyParentComponents.userName name="Himanshu" /&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, that's it for JSX, and now let's understand about the props &amp;amp; another several things about JSX:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can also pass JavaScript expressions as a prop by using curly braces. For an example: , as it is in curly braces, it will be evaluated first, and then it becomes 6&lt;/li&gt;
&lt;li&gt;You can not use if-else and loop in expression, as these are not valid expressions, so put in the surrounding code.&lt;/li&gt;
&lt;li&gt;You can use the ternary conditional operator in the JSX.&lt;/li&gt;
&lt;li&gt;Instead of loops, you can use higher-order functions like map, reduce, filter, etc.&lt;/li&gt;
&lt;li&gt;You can use the spread operator to pass an object as a prop. For an example: &amp;lt;Hm numbers = {...numbers}&lt;/li&gt;
&lt;li&gt;Booleans, null, and undefined don't render&lt;/li&gt;
&lt;li&gt;Props come as JavaScript Objects in the function signature.&lt;/li&gt;
&lt;li&gt;Suppose you have to write JSX between the opening and closing tag, then that content between those tags is passed as a special prop which is the props.children, and you can access them in the parent component as well. Example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:

function ParentComp(props){
    return (
        return &amp;lt;h1&amp;gt;{props.children}&amp;lt;/h1&amp;gt;
)};

function ChildComp(){
    return (
        &amp;lt;ParentComp&amp;gt;I am Hero&amp;lt;/ParentComp&amp;gt;
)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>javascript</category>
      <category>devops</category>
    </item>
    <item>
      <title>Writing Clean Code in JavaScript - Variables</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Fri, 30 Jul 2021 03:46:07 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/clean-code-in-javascript-variables-11kh</link>
      <guid>https://dev.to/himanshukanojiya/clean-code-in-javascript-variables-11kh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt; This blog assumes, you have basic knowledge of JavaScript.&lt;/p&gt;

&lt;p&gt;This blog covers writing good variables names to maintain code cleanability in JavaScript. What is Variable?, Why writing good names variables crucial for program &amp;amp; Software? How to write a good name for variables? &lt;/p&gt;

&lt;p&gt;Did you know writing bad codes leads to a lack of productivity and unnecessary delays, and difficulties to add functionality in the software later. &lt;/p&gt;

&lt;p&gt;It might be easy to write quickly messy code but later it will add unnecessary delays and difficulties. &lt;/p&gt;

&lt;h3&gt;
  
  
  What are Variables?
&lt;/h3&gt;

&lt;p&gt;Variable's are like a container where we store values or program-related data and then access them later to use that data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why writing good variable names crucial for program/software?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;With a good name, you and other developers can easily distinguish what kind of value it has.&lt;/li&gt;
&lt;li&gt;With a good naming, you don't need to read variable full-body or scroll to that position where it has initialized to find what kind of value it has.&lt;/li&gt;
&lt;li&gt;With a good naming, you can have an idea about what variable is for what value.&lt;/li&gt;
&lt;li&gt;With a good naming, you don't have to write unnecessary comments in the code. For, an example: What value variable has, and it is for what&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;In the end, good naming will save your lot of time in future.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  So, how to write a good name for variables?
&lt;/h3&gt;

&lt;p&gt;Well, it depends on the value you are storing, but here are a few checks which you can use to write a good variables name in JavaScript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the value is an object, then use some descriptive name for it. An object can have many data about the users or person or can be a group of data. Example: userInfo, database, authenticatedUserData, etc.&lt;/li&gt;
&lt;li&gt;If the value is a number or string, use a descriptive name, like username, age.&lt;/li&gt;
&lt;li&gt;If the value is a boolean, use names that answer a true or false to questions. Example: isUserActive, isUserAuthenticated, isLoggedIn.&lt;/li&gt;
&lt;li&gt;If your value is constant, then follow the descriptive name pattern and declare it in uppercase.&lt;/li&gt;
&lt;li&gt;Don't write too long name where you have to scroll to read&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: The ability to write clean codes instantly comes with experience and practice. Don't force yourself too hard to do it, try to follow this principle slowly to adapt to these things. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>codequality</category>
      <category>devops</category>
    </item>
    <item>
      <title>Short checklist to decide when to useReducer &amp; useState hook in the components</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Wed, 28 Jul 2021 09:53:54 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/short-checklist-to-decide-when-to-usereducer-usestate-hook-in-the-components-ooj</link>
      <guid>https://dev.to/himanshukanojiya/short-checklist-to-decide-when-to-usereducer-usestate-hook-in-the-components-ooj</guid>
      <description>&lt;p&gt;useReducer() &amp;amp; useState() hooks, both of them are state management hooks which add interactivity in the app &amp;amp; component.&lt;/p&gt;

&lt;p&gt;But sometimes, it can be complicated to distinguish which hook we should use and in which cases we should consider useReducer or useState. So here are some things which you can use to distinguish what to use:&lt;/p&gt;

&lt;h3&gt;
  
  
  For useState:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Use it when you are dealing with JavaScript primitives as a state.&lt;/li&gt;
&lt;li&gt;Use it when you have simple logic to change the state.&lt;/li&gt;
&lt;li&gt;Use it when you don't want to separate business logic from the component.&lt;/li&gt;
&lt;li&gt;Use it when you have small applications. For example, taking input from the search field and then add it to the current state.&lt;/li&gt;
&lt;li&gt;Use it when you have different properties that don't affect each other or don't change each other in a correlated way.&lt;/li&gt;
&lt;li&gt;Use it when you have different state properties that can be managed by multiple state hooks easily, like a form submission.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  For useReducer:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Use it when you have JavaScript objects &amp;amp; arrays as the state.&lt;/li&gt;
&lt;li&gt;Use it when you have complex logic to change the state.&lt;/li&gt;
&lt;li&gt;Use it when you have a medium-sized application.&lt;/li&gt;
&lt;li&gt;Use it when you have different properties that are tied together then, these should be in one state object like a library management function (adding, issuing &amp;amp; removing book details)&lt;/li&gt;
&lt;li&gt;Use it when you have very complex business logic and hard to be done in component alone (help to avoid unnecessary deep nesting in the app component).&lt;/li&gt;
&lt;li&gt;Use it when you want to make the state more predictable.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Note (my views):
&lt;/h3&gt;

&lt;p&gt;Reducer function in useReducer is like a functional programming paradigm because of several reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pure function, takes input and always give an output&lt;/li&gt;
&lt;li&gt;Always return new state object, does not mutate the current state object (immutability)&lt;/li&gt;
&lt;li&gt;Outputs are predictable&lt;/li&gt;
&lt;li&gt;Binary in nature, takes two arguments (current state &amp;amp; action object) and return one state object as output&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is useEffect()?, How does it work? &amp; Why should we use useEffect()?</title>
      <dc:creator>Himanshu Kanojiya</dc:creator>
      <pubDate>Tue, 27 Jul 2021 12:25:37 +0000</pubDate>
      <link>https://dev.to/himanshukanojiya/what-is-useeffect-how-does-it-work-why-should-we-use-useeffect-way-to-use-it-147g</link>
      <guid>https://dev.to/himanshukanojiya/what-is-useeffect-how-does-it-work-why-should-we-use-useeffect-way-to-use-it-147g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt; Basic knowledge of React Js**&lt;/p&gt;

&lt;p&gt;This blog covers about useEffect hook. What is the useEffect hook? How to use (Syntax)? How does it work? When to use it?, and some common use cases of useEffect hook.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is useEffect()?
&lt;/h2&gt;

&lt;p&gt;Well, useEffect is React hook, which use to handle side effects functions (side Effects are those functions that interact with the outside world, or out of React Js ecosystem), and with useEffect, we can separate them into another Function.&lt;/p&gt;

&lt;p&gt;It is like a Functional programming concept, where we try to encapsulate side effects in other functions so that other Functions can stay pure/unaffected. &lt;/p&gt;

&lt;p&gt;useEffect hook must declare inside the component (top-level, don't declare them in the block), it will give several advantages (Thanks to closure):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It will have accessibility to those data that are required to use in side effects.&lt;/li&gt;
&lt;li&gt;It can also update the data later, based on the dependencies and changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Syntax:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(function sideEffect(){ 
    .....
}, [dependencies_array_element])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  About the Syntax:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The first argument in useEffect is to give side effects function.&lt;/li&gt;
&lt;li&gt;The second argument is the dependencies array which gives instructions to useEffect hook when to run and when to not. Let's see this more closely:

&lt;ul&gt;
&lt;li&gt;If you don't give dependences array, only pass the first argument, then useEffect runs whenever your component renders/re-renders.&lt;/li&gt;
&lt;li&gt;If you give an empty dependences array, then useEffect runs once(when your component renders the first time, after that, it will not run unless you refresh the page).&lt;/li&gt;
&lt;li&gt;If you give something in the dependencies array, then useEffect will run once by default after the component finish rendering. After that, whenever the value of elements in the dependences array change, then useEffect will run again. Example: [isItemHidden].&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;Well, whenever your components finish rendering, useEffects run unless you specified dependencies in the dependencies array. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why should we use useEffects()?
&lt;/h2&gt;

&lt;p&gt;Well, there are several cases where you should consider useEffects. Some of them are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Suppose you are fetching some data online to display movie titles, ratings &amp;amp; you have used handler(Function with the synthetic event) or used inline Functions to get that data. So, what will happen is your component rendering will be stuck when the thread of execution reaches this point until you get the data from outside of the world.&lt;/li&gt;
&lt;li&gt;By seeing the first point, we can move those side effects to the useEffect hook so that our components can load/render. After completing the rendering process, React Engine will fire the useEffect hook to run the side effects code and update the component data.&lt;/li&gt;
&lt;li&gt;We should useEffect, when your component depends on the outside world data, and we can not guarantee that data will come or not (maybe the server is down there). So, Instead of throwing errors and stop other components from being rendered, move them into useEffect hook.&lt;/li&gt;
&lt;li&gt;When you are using browser API (including Timer function, fetch API, local storage and for more browser API, refer to this: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API" rel="noopener noreferrer"&gt;MDN Browser API&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Some use cases of React useEffect hook:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Always run whenever component renders/re-renders&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68epyhanf4bx9ytjpgbl.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68epyhanf4bx9ytjpgbl.PNG" alt="Render Always"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run once after that if component re-renders, then it will not run&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffftxr98h53v29fjd0as2.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffftxr98h53v29fjd0as2.PNG" alt="Render Once"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run once by default after that if prop values changes, then run&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpolmmx0twuk5i6uikfov.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpolmmx0twuk5i6uikfov.PNG" alt="Render if prop value changes"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run once by default after that if state changes than run&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtrno5brjut3k4dm6dvm.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtrno5brjut3k4dm6dvm.PNG" alt="Render if state changes"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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