<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Code of Relevancy on Medium]]></title>
        <description><![CDATA[Stories by Code of Relevancy on Medium]]></description>
        <link>https://medium.com/@codeofrelevancy?source=rss-d552f1544dab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KTLACxLA_oYJgFaErp2CRQ.png</url>
            <title>Stories by Code of Relevancy on Medium</title>
            <link>https://medium.com/@codeofrelevancy?source=rss-d552f1544dab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 16 May 2026 21:24:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codeofrelevancy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[What is prop drilling in React?]]></title>
            <link>https://medium.com/@codeofrelevancy/what-is-prop-drilling-in-react-2c0331326223?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c0331326223</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 05:36:10 GMT</pubDate>
            <atom:updated>2023-04-05T05:36:10.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*TGuiVGX-uz9xtM3JRdO6xA.png" /></figure><p>Yo ho, my hearties!!!</p><p>Prop drilling is the process of passing down data or state through multiple layers of a component hierarchy. By the way, it refers to the practice of passing data from a parent component to its children and then from the children to their own children and so on, until the data reaches the desired component that needs it..</p><p>Prop drilling can be a necessary and effective way to manage application state, it can also become a problem when the hierarchy of components becomes too deep or complex. This can lead to several issues. Let’s say, code duplication, increased cognitive load and decreased maintainability..</p><p>With this article, we will discuss what are props, what prop drilling is and how it can impact your application. We will also explore some best practices for fixing prop drilling in your codebase..</p><p>The horizon’s embrace, with the wind at our back and the sun on our face. Let’s set sail into the depths of prop drilling..</p><h3>What are Props in React?</h3><p>Props (aka “Properties”) are inputs to components. They are single values or objects containing a set of values that are passed to components on creation similar to HTML tag attributes. Here, the data is passed down from a parent component to a child component.</p><p>Props are <strong>read-only</strong>, meaning that they cannot be modified by the component itself. Used to customize the behavior or appearance of a component and they are passed down through the component tree in a unidirectional flow.</p><p>To show you what I mean..</p><pre>function Snake(props) {<br>  return &lt;h1&gt;Hello, {props.name}!&lt;/h1&gt;;<br>}<br><br>function DeadliestSnakes() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Snake name=&quot;Inland Taipan&quot; /&gt;<br>      &lt;Snake name=&quot;King Cobra&quot; /&gt;<br>      &lt;Snake name=&quot;Russell&#39;s Viper&quot; /&gt;<br>      &lt;Snake name=&quot;Black Mamba&quot; /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Let’s Understand the Prop Drilling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*S35gyvD3UD8D3lVE.gif" /><figcaption>Prop Drilling</figcaption></figure><p>Prop drilling occurs when a parent component passes data down to its children and then those children pass the same data down to their own children. This process can continue indefinitely. At the end, it’s a long chain of component dependencies that can be difficult to manage and maintain.</p><p>Let’s say you have a component that displays a list of blog posts. Each blog post has a title, date, author and content. In order to display this information, the parent component would need to pass down all of this data to its child components and those child components would need to pass it down to their own children and so on..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*JOOmHWDYZu1riAXa.png" /></figure><p>As you can imagine, this process can become quite complex and unwieldy, especially as your application grows in size and complexity..</p><h3>The Problems with Prop Drilling</h3><p>Prop drilling can lead to several issues in your codebase, let’s bring it on surface:</p><h3>Code Duplication</h3><p>When data needs to be passed down through multiple layers of components, it can result in code duplication. This occurs when the same data is passed down to multiple child components, even though they may not need all of it.</p><p>This can lead to bloated and redundant code which can be difficult to maintain and debug..</p><h3>Increased Cognitive Load</h3><p>Prop drilling can also increase the cognitive load on developers who need to understand and navigate the component hierarchy. As the number of components and layers increases, it can become difficult to keep track of which components are passing which data and where that data is being used.</p><p>This can make it more difficult to identify and fix bugs, as well as to make changes or updates to the codebase.</p><h3>Decreased Maintainability</h3><p>Prop drilling can lead to decreased maintainability over time. As your application grows in size and complexity, it can become more difficult to add new features or make changes to existing ones.</p><p>At the end, a codebase that is difficult to work with, which can lead to decreased productivity and increased frustration for developers.</p><h3>A Hunt of Prop Drilling for Cleaner React Code</h3><p>There are several ways that you can follow to fix prop drilling in your codebase. Let’s bring it on surface:</p><h3>Use a State Management Library</h3><p>One of the most effective ways to fix prop drilling is to use a state management library, such as <a href="https://redux.js.org/">Redux</a> or <a href="https://mobx.js.org/README.html#introduction">MobX</a>. These libraries provide a centralized store for managing application state which can help to eliminate the need for prop drilling.</p><p>Instead of passing data down through multiple layers of components, you can simply connect each component to the store, and access the data that you need directly..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*KYo1CaGBeoFq2UjG.gif" /><figcaption>Fix Prop Drilling</figcaption></figure><p>You could refactor your code to use Redux:</p><ul><li>Define a Redux store that holds the list of tasks:</li></ul><pre>import { createStore } from &quot;redux&quot;;<br><br>const initialState = {<br>  snakes: [],<br>};<br><br>function rootReducer(state = initialState, action) {<br>  switch (action.type) {<br>    case &quot;ADD_SNAKE&quot;:<br>      return {<br>        ...state,<br>        snakes: [...state.snakes, action.payload],<br>      };<br><br>    case &quot;DELETE_SNAKE&quot;:<br>      return {<br>        ...state,<br>        snakes: state.snakes.filter((snake) =&gt; snake.id !== action.payload.id),<br>      };<br><br>    case &quot;TRACK_SNAKE&quot;:<br>      return {<br>        ...state,<br>        snakes: state.snakes.map((snake) =&gt; {<br>          if (snake.id === action.payload.id) {<br>            return { ...snake, tracked: true };<br>          } else {<br>            return snake;<br>          }<br>        }),<br>      };<br><br>    default:<br>      return state;<br>  }<br>}<br><br>const store = createStore(rootReducer);</pre><ul><li>Connect your components to the Redux store using the connect() function:</li></ul><pre>import { connect } from &quot;react-redux&quot;;<br><br>function SnakeList(props) {<br>  const { snakes } = props;<br><br>  return (<br>    &lt;ul&gt;<br>      {snakes.map((snake) =&gt; (<br>        &lt;Snake key={snake.id} snake={snake} /&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}<br><br>function mapStateToProps(state) {<br>  return {<br>    snakes: state.snakes,<br>  };<br>}<br><br>export default connect(mapStateToProps)(SnakeList);</pre><ul><li>Dispatch Redux actions to add, delete or track snakes:</li></ul><pre>function Snake({ snake, deleteSnake, trackSnake }) {<br>  const onTrackSnake = (id) =&gt; () =&gt; {<br>    trackSnake(id);<br>  };<br>  <br>  const onDeleteSnake = (id) =&gt; () =&gt; {<br>    deleteSnake(id);<br>  };<br><br>  return (<br>    &lt;li&gt;<br>      &lt;input<br>        type=&quot;checkbox&quot;<br>        checked={snake.tracked}<br>        onChange={onTrackSnake(snake.id)}<br>      /&gt;<br>      {snake.title} ({snake.tracked ? &quot;Tracked&quot; : &quot;Not Tracked&quot;})<br>      &lt;button onClick={onDeleteSnake(snake.id)}&gt;Delete&lt;/button&gt;<br>    &lt;/li&gt;<br>  );<br>}<br><br>function mapDispatchToProps(dispatch) {<br>  return {<br>    deleteSnake: (id) =&gt; dispatch({ type: &quot;DELETE_TASK&quot;, payload: { id } }),<br>    trackSnake: (id) =&gt; dispatch({ type: &quot;TRACK_SNAKE&quot;, payload: { id } }),<br>  };<br>}<br><br>export default connect(null, mapDispatchToProps)(Snake);</pre><h3>Implement Context API</h3><p>If you don’t want to use a full fledged state management library, you can also consider using the <a href="https://react.dev/learn/passing-data-deeply-with-context#step-1-create-the-context">Context API</a> in React. This API provides a way to share data between components without the need for prop drilling.</p><p>Using the Context API, you can create a context object that holds the data that you need to share. You can then pass this context object down to the child components that need it, without having to pass it down through..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*HSEjPj3htmEdHS-h.png" /></figure><p>You could use the Context API to share a snake object between components:</p><ul><li>Create a snake context object:</li></ul><pre>import { createContext } from &#39;react&#39;;<br><br>export const SnakeContext = createContext({<br>  name: &quot;Black Mamba&quot;,<br>  fangs: &quot;6.5 mm&quot;,<br>  speed: &quot;12.5 miles per hour&quot;,<br>  color: &quot;#964B00&quot;, // dark brown<br>});</pre><ul><li>Wrap your components in a provider component that provides the snake context:</li></ul><pre>function Jungle(props) {<br>  const snake = {<br>    name: &quot;Black Mamba&quot;,<br>    fangs: &quot;6.5 mm&quot;,<br>    speed: &quot;12.5 miles per hour&quot;,<br>    color: &quot;#964B00&quot;, // dark brown<br>  };<br><br>  return (<br>    &lt;SnakeContext.Provider value={snake}&gt;<br>      &lt;Header /&gt;<br>      &lt;Main /&gt;<br>    &lt;/SnakeContext.Provider&gt;<br>  );<br>}</pre><ul><li>Use the useContext() hook to access the snake object in your child components:</li></ul><pre>import { useContext } from &quot;react&quot;;<br><br>function Header() {<br>  const { color } = useContext(SnakeContext);<br>  <br>  return (<br>    &lt;header style={{ backgroundColor: color }}&gt;<br>      &lt;h1&gt;Snake&lt;/h1&gt;<br>    &lt;/header&gt;<br>  );<br>}<br><br>function Main() {<br>  const { name, fangs, speed } = useContext(SnakeContext);<br>  <br>  return (<br>    &lt;main&gt;<br>      &lt;p&gt;<br>        Name: &lt;span&gt;{name}&lt;/span&gt;<br>      &lt;/p&gt;<br>      &lt;p&gt;<br>        Venom Fangs: &lt;span&gt;{fangs}&lt;/span&gt;<br>      &lt;/p&gt;<br>      &lt;p&gt;<br>        Speed: &lt;span&gt;{speed}&lt;/span&gt;<br>      &lt;/p&gt;<br>    &lt;/main&gt;<br>  );<br>}</pre><p>Context is not limited to static values. If you pass a different value on the next render, React will update all the components reading it below!!! This is why context is often used in combination with state.</p><p><strong><em>Use cases for context:</em></strong></p><ol><li>Theming</li><li>Current account</li><li>Managing state</li></ol><p>If some information is needed by distant components in different parts of the tree, it’s a good indication that context will help you..</p><p>In the vast ocean of React development, prop drilling can be a stormy challenge to navigate through.. But my fellow captains, fear not! With the right tools and techniques, you can hoist the sails of clean and efficient code and steer your React application towards smoother waters⛵️🌊</p><p>Happy coding and smooth sailing on your React adventures!!! 🚀🌟🌈🏴‍☠️</p><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*dCCqlHRbUmwhsM3c.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://discord.com/invite/f8jwnzcRz2">Discord</a><br><a href="https://github.com/codeofrelevancy">GitHub</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xVuUDYadbxnrSb1o.png" /><figcaption>Thank you</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c0331326223" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You Need to Know About Pure Functions & Impure Functions in JavaScript]]></title>
            <link>https://medium.com/@codeofrelevancy/you-need-to-know-about-pure-functions-impure-functions-in-javascript-19c3008ea8c5?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c3008ea8c5</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 06:26:23 GMT</pubDate>
            <atom:updated>2023-03-28T06:26:23.464Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ZTLoSDvouk2pv3PILH3ABQ.png" /></figure><p>With this article, we will explore what pure/impure functions are and their differences in JavaScript. Let’s dive in..</p><h3>What is a function?</h3><p>In the ocean of JavaScript, functions are an essential building block for creating complex and interactive apps.</p><p>One of the most common uses of functions is mapping, where they take input values and produce corresponding output values. This allows for the transformation and manipulation of data, which is critical in creating dynamic user experiences.</p><h3>What is a pure function?</h3><p>A pure function is a function where the return value is only determined by its arguments without any side effects. Let’s say, if you call a function with the same arguments n number of times and n number of places in the application then it will always return the same value. Pure functions do not modify any external state, such as variables or objects outside the function. They only use the input arguments to perform calculations and return the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*v5HTg4cwBXvoJK8j.gif" /></figure><p>To show you what I mean..</p><p>Below function takes two numbers, a and b, as input arguments and returns their sum. This function is a pure function because it always produces the same output for the same input and does not have any side effects.</p><pre>function add(a, b) {<br>  return a + b;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*j9WZA3t_KHztLQxX.png" /></figure><h3>What is an impure function?</h3><p>An impure function is a type of function, given the same input, may produce different output at different times. This is because impure functions can rely on external factors such as changes in global variables or other functions, that affect their behavior and output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*CSNZngA_VT78W6Tu.gif" /></figure><p>Below function modifies the external variable counter by increasing its value by one each time it is called. This means that it has side effects and is not a pure function.</p><pre>let counter = 0;<br><br>function increment() {<br>  counter++;<br>  return counter;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ZFd8e4xwdXBzyLUv.png" /></figure><h3>Why are pure functions useful?</h3><p>Pure functions have several advantages over impure functions:</p><p><strong>1) Predictability</strong><br>Because pure functions always produce the same output for a given input, they are predictable and easy to reason about. Its easier to test and debug and reduces the likelihood of unexpected behavior in your code.</p><p><strong>2) Reusability</strong><br>Pure functions are modular and self contained, meaning that they can be reused in different parts of your codebase without affecting other parts. This can save time and reduce the amount of code you need to write.</p><p><strong>3) Parallelization</strong><br>Because pure functions do not modify external state, they can be executed in parallel without worrying about race conditions or other synchronization issues. This can lead to faster and more efficient code.</p><h3>How to create pure functions in JavaScript?</h3><p><strong>1) Use only input arguments</strong><br>Pure functions should use only their input arguments to perform calculations and return the result. They should not modify any external state or rely on external variables.</p><p><strong>2) Avoid side effects</strong><br>Pure functions should not have any side effects, such as modifying external variables or objects. They should only return a value based on the input arguments.</p><p><strong>3) Avoid global state</strong><br>Pure functions should avoid using global state, such as global variables or objects. This can make your code less predictable and harder to debug.</p><p><strong>4) Return a value</strong><br>Pure functions should always return a value based on the input arguments. They should not rely on external variables or objects to produce their output.</p><h3>Pure vs Impure Functions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ckq-Sl2uP6w1uL9h.png" /></figure><h3>Inbuilt pure functions in JavaScript:</h3><p><strong>Math.abs():</strong> Returns the absolute value of a number.</p><p><strong>Math.ceil():</strong> Returns the smallest integer greater than or equal to a given number.</p><p><strong>Math.floor():</strong> Returns the largest integer less than or equal to a given number.</p><p><strong>Math.max():</strong> Returns the maximum value from a set of numbers.</p><p><strong>Math.min():</strong> Returns the minimum value from a set of numbers.</p><p><strong>Math.round():</strong> Returns the nearest integer to a given number.</p><p><strong>Math.sqrt():</strong> Returns the square root of a given number.</p><p><strong>parseInt():</strong> Converts a string to an integer.</p><p><strong>parseFloat():</strong> Converts a string to a floating point number.</p><p><strong>JSON.parse():</strong> Converts a JSON string to a JavaScript object.</p><p><strong>Array.prototype.concat():</strong> Returns a new array that contains the elements of the original array plus any additional elements that were passed in as arguments.</p><p><strong>Array.prototype.slice():</strong> Returns a new array that contains a portion of the original array, specified by a start and end index.</p><p><strong>Array.prototype.map():</strong> Returns a new array that is the result of calling a provided function on each element of the original array.</p><p><strong>Array.prototype.filter():</strong> Returns a new array that contains only the elements of the original array that satisfy a provided testing function.</p><p><strong>Array.prototype.reduce():</strong> Returns a single value that is the result of applying a provided function to each element of the array.</p><p><strong>String.prototype.toUpperCase():</strong> Returns a new string that contains the original string in all uppercase letters.</p><p><strong>String.prototype.toLowerCase():</strong> Returns a new string that contains the original string in all lowercase letters.</p><h3>Inbuilt impure functions in JavaScript:</h3><p><strong>Math.random():</strong> Returns a random number between 0 and 1. This function relies on external state which is the current state of the random number generator and its output changes every time it is called.</p><p><strong>Date.now():</strong> Returns the current timestamp which is the number of milliseconds that have elapsed since January 1, 1970. This function relies on external state which is the current time and its output changes every time it is called.</p><p><strong>console.log():</strong> Writes a message to the console. It does not return a value but it has a side effect of logging information to the console.</p><p><strong>setTimeout():</strong> Executes a function after a specified delay which is specified in milliseconds. This function has a side effect of scheduling a function to be executed in the future.</p><p><strong>setInterval():</strong> Executes a function at a specified interval which is specified in milliseconds. This function has a side effect of scheduling a function to be executed repeatedly at a fixed interval.</p><p><strong>document.write():</strong> Writes HTML content to the document. It does not return a value but it has a side effect of modifying the document.</p><p><strong>Math.floor(Math.random() * (max — min + 1) + min):</strong> Returns a random integer between a given range. This function relies on external state which is the current state of the random number generator and its output changes every time it is called.</p><p><strong>Math.pow():</strong> Returns the result of raising a number to a given power. While this function is mathematically pure, it may result in floating point rounding errors that can make its output impure.</p><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*CXazQPOpfCVmnIsE.gif" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://discord.com/invite/f8jwnzcRz2">Discord</a><br><a href="https://github.com/codeofrelevancy">GitHub</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*lpcmADMhzGfGZjc7.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c3008ea8c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Strict Mode in React?]]></title>
            <link>https://medium.com/@codeofrelevancy/what-is-strict-mode-in-react-cc8b51fb6096?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc8b51fb6096</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 16:54:27 GMT</pubDate>
            <atom:updated>2023-03-24T16:54:27.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*cptFvxz77ELdtN4G6E_qcw.png" /></figure><p>Hello React developers, you’ve probably heard of <strong>strict mode</strong>. But what the hell is it, exactly? In short term, React.StrictMode is a useful component for highlighting potential problems in an application. Just like &lt;Fragment&gt;, &lt;StrictMode&gt; does not render any extra DOM elements.. With this article, we&#39;ll dive into the details of what strict mode is, how it works and why you should consider using it in your applications..</p><h3>What is Strict Mode in React?</h3><p>Strict mode is a set of development tools that help you catch potential problems in your code before they become actual bugs. When you enable strict mode in your React application, you’re essentially telling React to turn on a bunch of extra checks👀 and warnings that are designed to help you write better code. These checks and warnings can catch things like:</p><ol><li>Components with side effects</li><li>Deprecated or unsafe lifecycle methods</li><li>Unsafe use of certain built in functions</li><li>Duplicate keys in lists</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*jBquL-D_JeVlmOj8.gif" /><figcaption>What is Strict Mode in React?</figcaption></figure><h3>Enabling Strict Mode?</h3><p>Enabling strict mode in your React application is actually very easy. You can do it by adding a single line of code to your main index.js file. Let&#39;s see:</p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br><br>ReactDOM.render(<br>  &lt;React.StrictMode&gt;<br>    &lt;App /&gt;<br>  &lt;/React.StrictMode&gt;,<br>  document.getElementById(&#39;root&#39;)<br>);</pre><h3>Enabling strict mode for a part of the app</h3><p>You can also enable Strict Mode for any part of your application:</p><pre>import { StrictMode } from &#39;react&#39;;<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Header /&gt;<br>      &lt;StrictMode&gt;<br>        &lt;main&gt;<br>          &lt;Sidebar /&gt;<br>          &lt;Content /&gt;<br>        &lt;/main&gt;<br>      &lt;/StrictMode&gt;<br>      &lt;Footer /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>In this instance, Strict Mode checks will not run against the Header and Footer components. But, they will run on Sidebar and Content, as well as all of the components inside them, no matter how deep it is..</p><h3>Strict mode affects only the development environment</h3><p>It’s important to note that strict mode has no effect on the production build of your React application. This means that any checks or warnings that are enabled by strict mode will not be present in the final version of your application that users see. As we have seen, strict mode turns on extra checks and warnings, it can potentially slow down your development environment..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*EiD-bhapfXKu9IEN.gif" /><figcaption>Strict mode affects only the development environment</figcaption></figure><h3>Strict mode can help you catch subtle bugs</h3><p>Sometimes bugs in React applications can be difficult to track down, especially if they’re caused by subtle issues like race conditions or incorrect assumptions about component state. By enabling strict mode and taking advantage of the extra checks and warnings it provides, you may be able to catch these bugs before they cause serious problems..</p><h3>Strict mode can help you stay up-to-date with best practices</h3><p>React is a rapidly evolving framework and best practices can change over time. By enabling strict mode and paying attention to the warnings and suggestions it provides, you can ensure that your React code is up-to-date and following current best practices. Such as using the key prop when rendering lists or avoiding side effects in render()..</p><h3>Highlighting potential problems early</h3><p>Strict mode can catch issues in your code that may cause problems in coming future, before they become serious problems. Let’s say, it can detect and warn about deprecated lifecycle methods as well as access to <a href="https://react.dev/reference/react-dom/findDOMNode">findDOMNode()</a> which is no longer recommended..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*TrIEtR6aaRfGKzBV.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*TJEf_J_q2bLR2IH0.png" /></figure><h3>Preventing common mistakes</h3><p>By enabling strict mode, you can avoid common mistakes that may not be immediately obvious, such as modifying the state directly instead of using setState() or using undeclared variables.</p><h3>Identifying Unsafe Lifecycles</h3><p>React Strict Mode can help identify the use of unsafe lifecycle methods in your components. For instance, it can warn you about the use of the componentWillUpdate and componentWillReceiveProps methods which are both considered unsafe and will be removed in future versions of React..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UUj395GeceTcG90c.png" /></figure><h3>Warning About Legacy String ref API Usage</h3><p>React Strict Mode can also warn you about the use of the legacy string ref API, which is considered deprecated. But, you should use the createRef API, which is safer and easier to use..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*dCzNlhoyHcuCECPy.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*skGG6GT3H2P8ojcc.png" /></figure><h3>Detecting Legacy Context API</h3><p>The <a href="https://legacy.reactjs.org/docs/legacy-context.html">legacy Context API</a> is deprecated in React and has been replaced with the new Context API. React Strict Mode can help you detect any usage of the legacy Context API and encourage you to switch to the <a href="https://react.dev/reference/react/useContext">new API</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*MvHUMww2ty1NwHyx.png" /></figure><p>If you’re not already using strict mode, it’s definitely worth considering!!!</p><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*isLftGhYDyrg2HlL.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://discord.com/invite/f8jwnzcRz2">Discord</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UHqDd_PQ3TmVRmKP.png" /><figcaption><a href="https://www.youtube.com/@codeofrelevancy">https://www.youtube.com/@codeofrelevancy</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc8b51fb6096" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unexpected Moments of JavaScript That Will Challenge Your Understanding of the Language]]></title>
            <link>https://medium.com/@codeofrelevancy/unexpected-moments-of-javascript-that-will-challenge-your-understanding-of-the-language-1ac93efe36d1?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ac93efe36d1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Sat, 18 Mar 2023 10:07:25 GMT</pubDate>
            <atom:updated>2023-03-18T10:07:25.115Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*HG1qIni02MioGUSX89aZUQ.png" /></figure><p>As one of the most popular programming languages in the world, <a href="https://www.javascript.com/">JavaScript</a> is widely used for building dynamic and interactive websites, web applications and even desktop and mobile applications. JavaScript is <strong>a gateway to other web technologies</strong>, because of its widespread use and compatibility with various platforms. It has become a foundational language in modern web development. It is also a complex language with many unexpected moments that can leave even the most experienced developers scratching their heads.</p><p>In this article, we’ll see various unexpected JavaScript moments that can confuse, test your limits and frustrate you. It will also help you to change the way you code.</p><p>Are you ready to make your brain explode🤯? If so, let’s enter the jungle..</p><p>1️⃣</p><pre>2 == [2] // true</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality">== operator</a> in JS performs type coercion which means it tries to convert the values being compared to a common data type before making the comparison.</p><p>In this instance, the number 2 is converted to a string and the array [2] is converted to a string as well. Resulting in both values being 2. That&#39;s why, the comparison evaluates to true.</p><p>It’s generally recommended to use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality">strict equality operator </a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality">===</a> instead of == to avoid unexpected results due to type coercion..</p><p>Explore more:</p><pre>&#39;123&#39; == 123        // true <br>&#39;foo&#39; == NaN        // false<br>undefined == null   // true <br>NaN === NaN         // false<br>NaN == NaN          // false<br>0 == null           // false</pre><p>2️⃣</p><pre>[] == ![] // true</pre><p>Comparing an empty array [] with a boolean value created by negating (using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT">! operator</a>) a non empty array []. The result of this comparison is true, which might seem unexpected at first glance..</p><p>In JS, every value can be either true or false in a boolean context. An empty array is a truthy value, which means it&#39;s considered true in a boolean context. When we apply the ! operator to it, it&#39;s converted to false.</p><p>On the other side, the boolean value created by negating a non empty array is false. When we compare an empty array (truthy) with a false value (falsy) using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality">== operator</a>, JS performs type constraint which means it tries to convert the values to a common type before comparing them. So, the empty array is converted to false which results in both sides being false. At the end, the comparison returns true.</p><p>Explore more:</p><pre>[&#39;a&#39;, &#39;b&#39;] !== [&#39;a&#39;, &#39;b&#39;]   // true<br>[&#39;a&#39;, &#39;b&#39;] == [&#39;a&#39;, &#39;b&#39;]    // false<br>[1, 2] + [3, 4]             // &quot;1,23,4&quot;</pre><p>3️⃣</p><pre>null == undefined // true</pre><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality">double equals </a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality">== operator</a> is used to compare two values for equality, while ignoring their data type. When comparing the values null and undefined using the double equals operator they are considered equal and the result of the comparison will be true. This is because both null and undefined represent a lack of a value and are so equivalent to each other in this context.</p><p>With strict equality operator:</p><pre>null === undefined // false</pre><p>4️⃣</p><pre>typeof NaN   // number<br>typeof null  // object</pre><p>In JS, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a> is an operator used to determine the type of a value or variable.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN">NaN</a> stands for <strong>Not a Number</strong> and is a special value in JS that represents an undefined or unrepresentable numerical value.</p><p>When you use typeof with NaN, it will return number. This might seem strange but it&#39;s because NaN is technically a numeric data type in JS even though it represents something that isn&#39;t actually a number.</p><p>When typeof is applied to null, it returns the string object. This is because null is considered to be a special value that represents an empty object reference. null is not an object itself but rather a primitive value. This is considered to be a quirk or oddity in the language design of JS.</p><p>Explore more:</p><pre>typeof function(){}     // &quot;function&quot;<br>null instanceof Object  // false</pre><p>5️⃣</p><pre>true == &quot;1&quot;  // true<br>false == &quot;0&quot; // true</pre><p>JS converts the string 1 to the boolean value true and string 0 to false because any non empty string is considered <em>truthy</em> and on other side <em>falsy</em>. So, the comparison becomes true == true which is true and false == false which is true.</p><p>Explore more:</p><pre>1 + true      // 2<br>1 - true      // 0<br>&#39;&#39; == false   // true<br>0 == false    // true<br>true + false  // 1</pre><p>6️⃣</p><pre>&quot;1&quot; + 1    // &quot;11&quot;<br>2 + &quot;2&quot;    // &quot;22&quot;<br>&quot;5&quot; - 3    // 2</pre><p>When you use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition">+ operator</a> with a string and a number, the number is converted to a string and concatenated to the string.</p><p>If the string can be parsed as a number, it will <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction">subtract</a> the number from the string.</p><p>So,<br>&quot;1&quot; + 1 becomes the string &quot;11&quot;<br>2 + &quot;2&quot; becomes the string &quot;22&quot;<br>&quot;5&quot; - 3 becomes the number 2</p><p>Explore more:</p><pre>+&quot;1&quot;                  // 1<br>-&quot;1&quot;                  // -1<br><br>+true                 // 1<br>-true                 // -1<br><br>+false                // 0<br>-false                // -0<br><br>+null                 // 0<br>+undefined            // NaN<br><br>1 / &quot;2&quot;               // 0.5<br>&quot;2&quot; / 1               // 2<br>1 / 0                 // Infinity<br>-1 / 0                // -Infinity<br>3 * &quot;abc&quot;             // NaN<br><br>true &gt; false          // true  <br><br>undefined + 1         // NaN<br>undefined - 1         // NaN<br>undefined - undefined // NaN<br>undefined + undefined // NaN<br><br>null + 1              // 1<br>null - 1              // -1<br>null - null           // 0<br>null + null           // 0<br><br>Infinity + 1          // Infinity<br>Infinity - 1          // Infinity<br>Infinity - Infinity   // NaN<br>Infinity + Infinity   // Infinity<br>Infinity / Infinity   // NaN</pre><p>7️⃣</p><pre>&quot;b&quot; + &quot;a&quot; + + &quot;a&quot; + &quot;a&quot; // &quot;baNaNa&quot;</pre><p>It concatenates the string b, the string a, the string resulting from the expression +&quot;a&quot; and the string a.</p><p>+&quot;a&quot; force the string a into a number which evaluates to NaN (Not a Number) because a is not a valid number.</p><p>When we concatenate b, a, NaN (represented as an empty string) and a, we get the string baNaNa.</p><p>8️⃣</p><pre>!{}       // false<br>{} == !{} // false<br>{} == {}  // false</pre><p>When, we are comparing an empty object {} to a negated empty object !{}. The exclamation mark ! is a logical operator that negates the value of the object so !{} returns false since an object is considered truthy in JS. We are actually comparing {} to false which results in a false value since they are not equal in value or data type.</p><p>In the last expression, we are comparing two empty objects {}. Despite the fact that they may appear to be identical, they are two separate objects with distinct references in memory so they are not equal in value or data type. In the end the comparison also results in a false value.</p><p>When you use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition"><strong>plus operator +</strong></a> between two objects wrapped in curly braces {}, it tries to concatenate the objects as strings.</p><p>Explore more:</p><pre>{} + [] === &quot;&quot;  // false<br>!!{}            // true <br>!![]            // true <br>[] + []         // &quot;&quot;<br>[] + {}         // &quot;[object Object]&quot;<br>{} + []         // &quot;[object Object]&quot;<br>{} + {}         // &quot;[object Object][object Object]&quot;<br>[] == false     // true<br>!!&#39;&#39;            // false<br>!!0             // false<br>!!null          // false<br>!!undefined     // false</pre><p>9️⃣</p><pre>7 &gt; 6 &gt; 5 // false</pre><p>First, 7 &gt; 6 evaluates to true because 7 is greater than 6.<br>Next, true &gt; 5 is evaluated. In JS, true is force into the number 1 and false is force into 0. So 1 &gt; 5 is false, since 1 is not greater than 5.</p><p>So at the end, 7 &gt; 6 &gt; 5 is equivalent to true &gt; 5 which is false.</p><p>Explore more:</p><pre>5 &lt; 6 &lt; 7  // true<br>0 &gt; null   // false</pre><p>1️⃣0️⃣</p><pre>Math.max() // -Infinity<br>Math.min() // Infinity</pre><p>Math.max() &amp; Math.min() are functions that can be used to find the largest and smallest values in a set of numbers respectively.</p><p>When called without any arguments, Math.max() returns -Infinity which represents the smallest possible number in JS, on other side, Math.min() returns Infinity which represents the largest possible number in JS.</p><p>This behavior makes sense because if there are no numbers provided, there is no largest number to return for Math.max() and following same way, there is no smallest number to return for Math.min()</p><p>1️⃣1️⃣</p><pre>parseInt(&#39;08&#39;)       // 8<br>parseInt(&#39;08&#39;, 10)   // 8 <br>parseInt(&#39;0x10&#39;)     // 16</pre><p>parseInt(&#39;08&#39;) converts the string 08 into the integer number 8. If you were to write parseInt(&#39;08&#39;, 10), the function will still return 8.</p><p>The reason behind this is because the second parameter of parseInt function is the radix which specifies the numbering system to be used. Let&#39;s say: binary, octal, decimal, hexadecimal etc.. If the radix is not specified parseInt will try to detect the radix based on the string format. In above case, 08 is considered an octal number because it starts with 0 so it gets converted into 8 as a decimal number.</p><p>parseInt(&#39;0x10&#39;) converts the hexadecimal string 0x10 into the integer number 16. The radix is not specified either, but the prefix 0x indicates that the number should be treated as a hexadecimal number so it gets converted into 16 as a decimal number.</p><p>Explore more:</p><pre>parseFloat(&#39;3.14.15&#39;)  // 3.14 <br>parseFloat(&#39;0.0&#39;)      // 0</pre><p>1️⃣2️⃣</p><pre>(function(x) { delete x; return x; })(1);   // 1</pre><p>An anonymous function that takes an argument x. Inside the function it tries to delete the x variable which is not possible because x is a function argument and cannot be deleted. The function then returns the value of x.</p><p>When this function is called with the argument 1, the value of x inside the function is set to 1. In this case, the delete operation has no effect, the function simply returns the value of x which is 1</p><p><em>Great job exploring and understanding these JavaScript concepts!!! This knowledge will definitely help you in interviews and enable you to assess the skills of potential candidates as an interviewer. Keep up the good work and continue learning something Ctrl+N</em></p><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*9ZPFHPYV_LVnlpDG.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*SSc5jKoTuKsA0y_ILbMtWg.png" /><figcaption>Dour Darcel #8740</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ac93efe36d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Tic Tac Toe Game using HTML, CSS, JavaScript, Tailwind CSS and Canvas Confetti]]></title>
            <link>https://medium.com/@codeofrelevancy/build-a-tic-tac-toe-game-using-html-css-javascript-tailwind-css-and-canvas-confetti-b33d5da1232d?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/b33d5da1232d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 14:49:08 GMT</pubDate>
            <atom:updated>2023-03-13T14:49:08.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*yhtWfA2qWczMSgKOl9bQpw.png" /></figure><p>Welcome to the Island of Relevancy.</p><p>Tic Tac Toe is a classic game that has been enjoyed by people for generations. It’s a simple game that can be played anywhere, anytime with just a pen and paper. But with modern technology we can take this game to the next level. In this video, we’ll explore how you can build a Tic Tac Toe game using HTML, CSS, JavaScript, Tailwind CSS and Canvas Confetti.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fq3uI-1nNGDU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dq3uI-1nNGDU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fq3uI-1nNGDU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/76ecf9eb950324600948b1f9fa889c43/href">https://medium.com/media/76ecf9eb950324600948b1f9fa889c43/href</a></iframe><p>To create the game board, we’ll use HTML and CSS. We’ll create a 3x3 grid of squares that players can click on to place their symbols. We’ll also use Tailwind CSS to style the board and make it responsive.</p><p>To make the board interactive, we’ll use JavaScript to handle player moves and game logic. When a player clicks on a square, we’ll check if the square is empty. If it is, we’ll place the current player’s symbol in the square and check if they have won. If there’s no winner yet, we’ll switch to the other player’s turn.</p><p>To make the game more personalized, we’ll add the ability for players to upload their own avatars. We’ll use the HTML5 file input tag to allow players to select an image from their local machine. We’ll then use JavaScript to display the selected image as the player’s avatar.</p><p>When a player wins, we’ll celebrate their victory with confetti animations, an animated Tic Tac Toe trophy over the winning player’s avatar and a highlight of the three squares that make up the winning line. We’ll use the Canvas Confetti library to create the confetti animations.</p><p>We’ll keep track of each player’s score using JavaScript and store it in the client side storage of the browser. This means that the scores will persist even if the player closes the page. We’ll also provide a “Reset Score” button that players can use to reset the scores to zero.</p><p>To reset the game after a victory or a draw, we’ll provide a “Reset Game” button that players can use to start a new game.</p><h3>How it works?</h3><p>The game starts with player X’s turn and they can click on an empty square to place their symbol. After player X makes their move, it becomes player O’s turn to place their symbol in an empty square. During each turn, the game shows a bounce animation on the current player’s name to indicate whose turn it is. This makes it easy for players to keep track of whose turn it is and adds a fun element to the game.</p><p>By default, you’ll see Davy Jones and Jack Sparrow representing X and O respectively. But if you want to personalize the game, you can upload your own avatars from your local machine. Note that the uploaded avatars won’t persist after a page refresh since there’s no database connectivity.</p><p>When a player wins, the game will display confetti animations over winner’s avatar and at the top of the page to celebrate the victory. The player’s avatar will also be adorned with an animated Tic Tac Toe trophy. And to help you see the winning move more clearly, the game will highlight the three squares that make up the line.</p><p>Each player has a score that increases by one after securing a victory. The scores are stored on the client side (in the local storage of your browser) so you can keep track of your progress even if you close the page. And if you ever want to start over, you can reset the scores to 0 for both players with a click of “Reset Score” button.</p><p>To reset the game after a victory, you can click the “Reset Game” button.</p><p>At the end of the game, players can download an image of the board with the winning trophy and the score. This image can be saved or shared with others.</p><p>In case the game ends in a draw, a popup message is displayed notifying you that the game ended in a draw.</p><h3><strong>📦 Demo:</strong></h3><p><a href="https://t3-game.vercel.app">https://t3-game.vercel.app</a></p><h3>⚓️App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*SAV1hR3sE0ceyhLt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qU9r7687qR2D09gl.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*XDsJLB8q-baVmPfr.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*jzJVlVZfM4MQyZwI.png" /></figure><p>So what are you waiting for? Let’s play some Tic Tac Toe!!!</p><h3>Files:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*EMnuS6W0onkTNSTt.png" /></figure><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*S7HIZkoSUwbgbhoY.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*d_42cp9C7orq33BUwYbm8w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b33d5da1232d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sail on a Sea of React Libraries That Will Make You the Captain of your Code]]></title>
            <link>https://medium.com/@codeofrelevancy/sail-on-a-sea-of-react-libraries-that-will-make-you-the-captain-of-your-code-e8c53683be7a?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8c53683be7a</guid>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Tue, 07 Mar 2023 05:08:47 GMT</pubDate>
            <atom:updated>2023-03-07T05:08:47.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*vWIqG71GXE17bsvdZRVL2g.png" /></figure><p>Ahoy there, As a React developer it’s always good to have a trusted library by your side. Just like the famous <strong>Pirates of the Caribbean</strong>, who had their trusty compasses and maps to navigate the seas. We have our libraries to navigate the world of React development. In this trip of sea of React libraries, we’ll take a look at some of the most popular libraries you should know as a React developer.</p><p><strong>Secure your ship for the storm ahead, let’s batten down the hatches together..</strong></p><h3>I. Redux — The Treasure Chest</h3><p>Just like a treasure chest that holds all the valuable treasure for the pirates, <a href="https://redux.js.org/">Redux</a> holds all the state data in your React app. It’s a predictable state container that helps you manage the state of your app in a structured way. Redux helps you maintain a single source of truth, making it easier to manage your app’s state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*bba34onMwhRo2Csh.png" /><figcaption><a href="https://redux.js.org/">https://redux.js.org/</a></figcaption></figure><p>To integrate Redux, you can install it using npm or yarn and then create a store with the createStore function.</p><p>To show you what I mean..</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Finteresting-ride-3xlcj2%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F3xlcj2&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F3xlcj2%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/73ed7cd5869f2ea6c0df83526a546aba/href">https://medium.com/media/73ed7cd5869f2ea6c0df83526a546aba/href</a></iframe><h3>II. Axios — The Parrot</h3><p>Just like a parrot that can deliver messages between different pirates. <a href="https://www.npmjs.com/package/axios">Axios</a> is a library that helps you send HTTP requests to a server. It’s a promise based library that makes it easy to communicate with APIs and fetch data for your app. Axios can be used in both client side and server side apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*b8NZbapJ_YmhsdmL.png" /><figcaption><a href="https://www.npmjs.com/package/axios">https://www.npmjs.com/package/axios</a></figcaption></figure><p>Let’s say you can use it to manage your app’s state in a centralized store. Yo ho, yo ho! It’s now easy to share data between components.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fquizzical-driscoll-i30mzd%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fi30mzd&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fi30mzd%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7eb663a3e413d1ff23a1d77b6d17465/href">https://medium.com/media/f7eb663a3e413d1ff23a1d77b6d17465/href</a></iframe><h3>III. React Spring — The Cannon</h3><p>Just like a cannon that provides firepower to a pirate ship, <a href="https://www.react-spring.dev/">react-spring</a> provides the firepower to your React components. It’s a library that makes it easy to add animation and interactivity to your components. With react-spring you can create fluid and dynamic animations that bring your app to life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UKeux65fpUxRZtzM.png" /><figcaption><a href="https://www.react-spring.dev/">https://www.react-spring.dev/</a></figcaption></figure><p>Let’s say you can use it to create smooth and dynamic animations and transitions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fbeautiful-ellis-3qen2d%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F3qen2d&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F3qen2d%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/676f01f7b3d7d95e1938634e3c6a8108/href">https://medium.com/media/676f01f7b3d7d95e1938634e3c6a8108/href</a></iframe><h3>IV. React Popper — The Telescope</h3><p>Just like a telescope that helps a pirate see things from a distance, <a href="https://popper.js.org/">react-popper</a> helps you position and align elements in your app. It’s a library that makes it easy to create tooltips, dropdowns and popovers in your React app. Using it you can create dynamic and interactive UI elements that enhance your app’s user experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*96Q799UWQtsUxH6-.png" /><figcaption><a href="https://popper.js.org/">https://popper.js.org/</a></figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Freact-popper-the-telescope-rlyz0c%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Frlyz0c&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Frlyz0c%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c56098e0f1240812faf4f4b0db336ffb/href">https://medium.com/media/c56098e0f1240812faf4f4b0db336ffb/href</a></iframe><h3>V. SWR — The Spyglass</h3><p>Just like a spyglass that helps a pirate see what’s ahead, <a href="https://swr.vercel.app/">SWR</a> helps you manage data fetching in your React app. It’s a library that provides a caching mechanism for data fetching. With SWR, it’s easy to manage and update data in real time and you can create fast and responsive apps that keep your users engaged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*fdSmzDsD5NxG9SHx.png" /><figcaption><a href="https://swr.vercel.app/">https://swr.vercel.app/</a></figcaption></figure><p>Components will get a stream of data updates constantly and automatically. The UI will be always fast and reactive.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fnostalgic-currying-7m3k36%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F7m3k36&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F7m3k36%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c3fc13c6ad9a76653833d133ec4219c/href">https://medium.com/media/8c3fc13c6ad9a76653833d133ec4219c/href</a></iframe><h3>VI. Recharts — The Sextant</h3><p>Just like a sextant that helps a pirate navigate the seas, <a href="https://recharts.org/en-US">Recharts</a> helps you navigate your data in your React app. It’s a library that provides a set of charting components that can be easily integrated into your app. With Recharts, you can create beautiful and dynamic charts that help you visualize and understand your data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*svK35RP9OTzOGkzw.png" /><figcaption><a href="https://recharts.org/en-US">https://recharts.org/en-US</a></figcaption></figure><p>You can refer to the tutorial below to view Recharts in action:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpDddqNRBu4s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpDddqNRBu4s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FpDddqNRBu4s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0be15cb7cb317da6cc150f7140464c50/href">https://medium.com/media/0be15cb7cb317da6cc150f7140464c50/href</a></iframe><h3>VII. Tailwind CSS — The Ship’s Flag</h3><p>Just like a ship’s flag that represents the identity and spirit of a pirate crew, <a href="https://tailwindcss.com/">TailwindCSS</a> represents the identity and style of your React components. It’s a utility-first CSS framework that allows you to quickly and easily style your components. With TailwindCSS, you can create beautiful and responsive designs without writing any CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*2wR5Jmq3saZfO6B7.png" /></figure><p>You can refer to the tutorial below to view Tailwind CSS in action:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2sGwtnnDhmM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2sGwtnnDhmM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2sGwtnnDhmM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f6fc40171d322e8df071570ac54ef33/href">https://medium.com/media/3f6fc40171d322e8df071570ac54ef33/href</a></iframe><h3>VIII. React Big Calendar — The Schedule Treasure</h3><p><a href="https://www.npmjs.com/package/react-big-calendar">react-big-calendar</a> helps you manage your schedule in your React app. It’s a library that provides a set of customizable calendar components that can be easily integrated into your application. With react-big-calendar, you can create dynamic and interactive calendars that help you manage your schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*gJ64a_aZ58178slb.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Freact-big-calendar-example-lrwm4%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fl9jwl0kj6m&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Flrwm4%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/afe0fcfe9bf3c271be77fd09ff90509f/href">https://medium.com/media/afe0fcfe9bf3c271be77fd09ff90509f/href</a></iframe><h3>IX. Prettier — The Ship’s Crew</h3><p>Just like a pirate crew that works together to keep the ship sailing smoothly, <a href="https://prettier.io/">Prettier</a> works together with other libraries to keep your React code formatted and consistent. It’s a library that provides a set of code formatting rules that can be easily integrated into your development workflow. With Prettier, you can ensure that your code is formatted consistently and is easy to read and maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*caU0tAx4fn-lzMaL.png" /></figure><p>To integrate Prettier, you can install it using <strong>npm</strong> or <strong>yarn</strong> and then add a .prettierrc file to your project with your desired configurations:</p><pre>{<br>  &quot;semi&quot;: true,<br>  &quot;trailingComma&quot;: &quot;all&quot;,<br>  &quot;singleQuote&quot;: true,<br>  &quot;printWidth&quot;: 80,<br>  &quot;tabWidth&quot;: 2<br>}</pre><h3>X. React Hook Form — The Compass</h3><p>Just like a compass that helps a pirate navigate their way, R<a href="https://react-hook-form.com/">eact Hook Form</a> is a library that helps you build forms in your React application. It’s a lightweight library that makes it easy to validate and manage form data in a simple and efficient way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*pdb52tQ287jNkOpp.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fupbeat-smoke-z2kbnv%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fz2kbnv&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fz2kbnv%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/70591f595e8919fcd9023eab6c24a389/href">https://medium.com/media/70591f595e8919fcd9023eab6c24a389/href</a></iframe><h3>XI. Framer Motion — The Jolly Roger</h3><p>Just like the Jolly Roger that represents a pirate crew, <a href="https://www.framer.com/motion">Framer Motion</a> represents your app’s animations and transitions. It’s a library that provides a set of animation and transition components that can be easily integrated into your app. With Framer Motion, you can create dynamic and engaging animations that bring your app to life such as page transitions, hover effects and scroll animations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Em2U2rRzgP3y7S7a.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Flively-sky-2szvm1%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F2szvm1&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F2szvm1%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/cad858bd527346c64b3dd0831b6e198e/href">https://medium.com/media/cad858bd527346c64b3dd0831b6e198e/href</a></iframe><h3>XII. React Spinners — The Anchor</h3><p>Just like an anchor that helps a pirate’s ship stay stable in rough seas, <a href="https://www.davidhu.io/react-spinners">React Spinner</a> helps you manage loading states in your React app. It’s a library that provides a set of customizable loading spinner components that can be easily integrated into your app. With React Spinner, you can create smooth and responsive loading states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ThQHvCw3Gw9nYaQZ.png" /></figure><p><a href="https://www.davidhu.io/react-spinners/storybook/?path=/docs/barloader--main">You can refer to the examples of storybook</a></p><h3>XIII. React Intl — The Parrot’s Tongue</h3><p>Just like a parrot that can speak different languages, <a href="https://www.npmjs.com/package/react-intl">React Intl</a> helps you internationalize your React app. It’s a library that provides a set of tools for formatting and displaying localized content. With React Intl, you can create apps that can be easily translated and localized for different regions and languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xghXVZXzWNRzLaIq.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fcool-paper-ui6rh9%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fui6rh9&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fui6rh9%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/72e7cfa8b97946ca7b5b234f156b4132/href">https://medium.com/media/72e7cfa8b97946ca7b5b234f156b4132/href</a></iframe><h3>XIV. Moment — Sailing the Seas of Time</h3><p><a href="https://momentjs.com/">MomentJS</a> is a JavaScript library which helps is parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way. This chapter will provide an overview of MomentJS and discusses its features in detail. Moment JS allows displaying of date as per localization and in human readable format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Q2d_AqGmUUAJtYJC.png" /></figure><pre>moment().format(&#39;MMMM Do YYYY, h:mm:ss a&#39;); // March 6th 2023, 7:25:45 pm<br>moment().format(&#39;dddd&#39;);                    // Monday<br>moment().format(&quot;MMM Do YY&quot;);               // Mar 6th 23<br>moment().format(&#39;YYYY [escaped] YYYY&#39;);     // 2023 escaped 2023<br>moment().format();                          // 2023-03-06T19:25:45+05:30</pre><h3>XV. Lodash — The Secret Weapon</h3><p><a href="https://lodash.com/">Lodash</a> library provides a set of utility functions that can help you simplify your code and make it more efficient. With Lodash, you can do things like iterate over arrays and objects, manipulate strings and numbers and perform other common tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*yP7fDDmqefk1E6py.png" /></figure><pre>import _ from &#39;lodash&#39;;<br><br>function MyComponent() {<br>  const numbers = [1, 2, 3, 4, 5];<br>  const sum = _.sum(numbers);<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;The sum of {numbers.join(&#39;, &#39;)} be {sum}&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>XVI. Formik: The Black Pearl</h3><p><a href="https://formik.org/">Formik</a> is third party React form library. It provides basic form programming and validation. It is based on controlled component and greatly reduces the time to do form programming. In ReactJS, the purpose of Formik is to create a scalable and performant form helper with a very simple API. Other React form management tools such as Redux Form are available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ydUq763p3BP546VA.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fformik-example-forked-4c2cv8%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F4c2cv8&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F4c2cv8%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/aac0a613122866f61f56c06c9df0a0a5/href">https://medium.com/media/aac0a613122866f61f56c06c9df0a0a5/href</a></iframe><p>You can refer to the tutorial below to see Formik in action:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2sGwtnnDhmM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2sGwtnnDhmM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2sGwtnnDhmM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f6fc40171d322e8df071570ac54ef33/href">https://medium.com/media/3f6fc40171d322e8df071570ac54ef33/href</a></iframe><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*QzFL6GlGhqFhYIEJ.png" /><figcaption>Motivation</figcaption></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*fFGQlBmOmCspGgFAb3vjZQ.png" /><figcaption>Thank you in advance for your support!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8c53683be7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an EMI Calculator with Next.js, TypeScript, Tailwind CSS, Recoil and Recharts]]></title>
            <link>https://medium.com/@codeofrelevancy/build-an-emi-calculator-with-next-js-typescript-tailwind-css-recoil-and-recharts-cedae215b07?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/cedae215b07</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Sat, 04 Mar 2023 05:02:37 GMT</pubDate>
            <atom:updated>2023-03-04T05:02:37.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*HcxOy6o0sO8z-izzFjji8w.png" /><figcaption><a href="https://youtu.be/pDddqNRBu4s">https://youtu.be/pDddqNRBu4s</a></figcaption></figure><p>Are you interested in building a next level and attractive EMI Calculator? If so, you’re in luck. Through this tutorial, we’ll explore how to create your own calculator using <strong>Next.js</strong>, <strong>TypeScript</strong>, <strong>Tailwind CSS</strong>, <strong>Recoil</strong> and <strong>Recharts</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpDddqNRBu4s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpDddqNRBu4s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FpDddqNRBu4s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0be15cb7cb317da6cc150f7140464c50/href">https://medium.com/media/0be15cb7cb317da6cc150f7140464c50/href</a></iframe><p>Let’s take a look at the tools we’ll be using.</p><p><a href="https://nextjs.org/">Next.js</a> is a popular JavaScript framework that allows you to build web applications with ease.</p><p><a href="https://www.typescriptlang.org/">TypeScript</a> is a powerful language that adds static typing to JavaScript which making it easier to write and debug code.</p><p><a href="https://tailwindcss.com/">Tailwind CSS</a> is a flexible and powerful CSS framework that makes it easy to style your applications.</p><p><a href="https://recoiljs.org/">Recoil</a> is a state management library that makes it easy to manage complex state in your application.</p><p><a href="https://recharts.org/">Recharts</a> is a charting library that allows you to create attractive and informative data visualizations.</p><p>At the moment we know what tools we’ll be using, let’s get started! We’ll need to set up our development environment. Make sure you have Node.js, Git and a code editor installed on your machine. My all time favorite editor is <a href="https://code.visualstudio.com/">VSCode</a>.<br>You can then create a new <strong>Next.js</strong> project using the command line. Make sure to include <strong>TypeScript</strong> in your project setup.</p><p>Going forward, we’ll install and set up Tailwind CSS. This will allow us to style our calculator and make it look next level. You can install Tailwind CSS using <strong>npm</strong> or <strong>yarn</strong> and then include it in your <strong>Next.js</strong> project. You can then create a simple layout for your calculator, including input fields for loan amount, interest rate and loan tenure.</p><p>Let’s add some functionality to our calculator using <strong>Recoil</strong>. We can use Recoil to create an atom for loan amount, interest rate and loan tenure. We can then use state atom to update the display of our calculator.</p><p>To make it more interesting, we can add some data visualization to our calculator using <strong>Recharts</strong>. We can create a simple pie chart that shows the user how their total payments will change over the course of the loan tenure. This can be a great way to help them understand the impact of their loan payments over time.</p><p>While these tools can be incredibly helpful in automating complex calculations, it’s important to thoroughly test your calculator and ensure that it is accurate and reliable. It’s important to remember that while technology can make our lives easier in many ways, it is not a substitute for human expertise and judgment. When it comes to making financial decisions, make sure to seek advice from qualified professionals and not rely solely on the results of a calculator.</p><h3>Why Next.js with Tailwind CSS?</h3><p>Next.js and Tailwind CSS are two popular technologies in the web development world. Next.js is a React based framework for building server side rendered (SSR) applications, on Other Side Tailwind CSS is a utility first CSS framework for building responsive and customizable UIs.</p><h4>Improved Developer Experience</h4><p>Next level benefit of using Next.js with Tailwind CSS is the improved developer experience it provides. With Tailwind CSS, you can easily style your components using pre defined utility classes instead of writing custom CSS code. This saves a lot of time and effort in the development process. Tailwind CSS comes with a built in JIT (Just In Time) compiler that compiles your CSS code on demand, which further reduces development time.</p><p>Next.js, on the other side, provides a great developer experience by providing features such as hot module replacement (HMR) and automatic code splitting. This means that changes made to your code are reflected in the browser immediately without the need for a page refresh. If I say more, Next.js automatically splits your code into smaller chunks, which makes your application load faster.</p><h4>Performance Optimization</h4><p>Performance is a crucial factor in web development and using Next.js with Tailwind CSS can help you optimize your app’s performance. With Tailwind CSS, you can write highly optimized CSS code that is lightweight and fast loading. This can lead to faster load times and better overall performance.</p><p>Next.js also provides a number of performance optimization features, such as server side rendering (SSR) and static site generation (SSG). With SSR, your app’s HTML is generated on the server instead of the client, which leads to faster load times and better SEO. SSG, on the other side, generates static HTML files for your app, which can be cached by the browser and served quickly to the user.</p><h4>Customization</h4><p>Tailwind CSS is highly customizable, I mean, that you can easily customize the framework to fit your specific needs. You can customize everything from the colors and fonts to the spacing and borders. It comes with a number of pre built themes and templates which can be a great starting point for your project.</p><p>Next.js is also highly customizable with a number of configuration options available for things like routing, server side rendering, and much more. This allows you to tailor your app to your specific needs and requirements.</p><h4>Seamless Integration</h4><p>Using Next.js with Tailwind CSS is a seamless experience with both technologies working together seamlessly. Next.js provides built in support for CSS modules, allows you to import your Tailwind CSS styles directly into your components. This makes it easy to use Tailwind CSS in your Next.js app without any extra setup.</p><p>Next.js provides a number of other features that make integrating with Tailwind CSS easy such as dynamic imports and code splitting. With these features you can ensure that only the necessary CSS code is loaded for each page, it can improve performance and reduce page weight.</p><p>📦 Demo:<br><a href="https://emi-calculator-cor.vercel.app/">EMI Calculator App</a></p><p>By following this article, you can create your own calculator and customize it to meet your needs.</p><h3>⚓️App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*eCYX6Y7SUM3BpgvA.png" /><figcaption><a href="https://emi-calculator-cor.vercel.app/">https://emi-calculator-cor.vercel.app</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*h8mAlFa5AUt3NLE3.png" /><figcaption><a href="https://emi-calculator-cor.vercel.app/">https://emi-calculator-cor.vercel.app</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UW1pOZVDrkOHf9CT.png" /><figcaption><a href="https://emi-calculator-cor.vercel.app/">https://emi-calculator-cor.vercel.app</a></figcaption></figure><h3>❤ Motivation:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*pln4XPuZO5zirRZQ.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ABmNA3nfNNNhDQqd8Wym6A.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cedae215b07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Take Your Code to The Other Side]]></title>
            <link>https://medium.com/@codeofrelevancy/take-your-code-to-the-other-side-12368872deb?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/12368872deb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code-refactoring]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Wed, 01 Mar 2023 09:51:43 GMT</pubDate>
            <atom:updated>2023-03-01T09:51:43.434Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qQBh8MnVLuWRwyXkixAHsg.png" /><figcaption>Take Your Code to The Other Side</figcaption></figure><p>In today’s adventure I will take you to the Other Side of code development. <strong>As ONE</strong>, we’ll explore the art of code refactoring and see how it can revolutionize your codebase. Sounds marvelous!!! After going through this adventure, you’ll learn how to transform your code from <strong>Good</strong> to <strong>Great</strong> or <strong>Great</strong> to <strong>Next level</strong>. You’re a developer and it’s your responsibility to take your application to new heights of performance, scalability and maintainability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qLSOj6jpoUXpKEJi.gif" /><figcaption>List of Contents</figcaption></figure><p>As software projects grow, it’s common for the codebase to become complex &amp; difficult to manage. At this point, code refactoring comes into light from the darkness. It’s the process of improving existing code by restructuring it in a more efficient and effective way without changing its behavior.</p><p>Refactoring does not add any new features or functionalities to the software or product. It can improve the quality, readability and maintainability of your codebase. Which makes it easier to work with in the long run.</p><h3>Why Refactor Your Code?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*uT1tAjsWyFUREpCB.gif" /><figcaption>Why Refactor Your Code?</figcaption></figure><p><strong>Improved Code Quality:</strong></p><blockquote><em>Refactoring improves code quality by reducing code complexity, removing duplication and improving the overall design of the code. This ends in code that is easier to read and understand, reducing the risk of introducing errors or bugs.</em></blockquote><p><strong>Increased Maintainability:</strong></p><blockquote><em>By reducing code complexity and improving the design of your code, refactoring makes it easier to maintain and update your code in the long term. This can save time and effort for developers working on the project and reduce the risk of introducing bugs when making changes.</em></blockquote><p><strong>Better Performance:</strong></p><blockquote><em>Refactoring can help improve the performance of your code by optimizing algorithms, removing unnecessary code and reducing resource usage. This can lead to faster execution times and improved efficiency.</em></blockquote><p><strong>Easier Collaboration:</strong></p><blockquote><em>By improving code quality and reducing complexity, refactoring can make it easier for developers to collaborate on a project. This can improve team productivity and reduce the risk of introducing errors or bugs when working on shared code.</em></blockquote><p>By moving forward on our adventure, it’s time to perform the code refactoring and <strong>break on through to the Other Side</strong>.</p><h3>Code Formatting</h3><p>It’s important to consider code formatting when working on a team or maintaining a codebase. Different developers may have varying preferences for indentation, line breaks and quotation marks. That ends in an inconsistent code style. Inconsistent code style can make the code look cluttered and challenging to read. So it’s crucial to maintain a consistent code style across the project.</p><p>It’s beneficial to use refactoring tools such as <a href="https://prettier.io/">Prettier</a>. In case you’re not familiar with Prettier, let’s break it.. <strong>Prettier</strong> is a popular and user friendly tool that automates code formatting. Once added to the project, it will take care of formatting the code according to pre set style settings. Also you can customize the formatting rules to your preference by creating a .prettierrc file with below configs:</p><pre>{<br>  &quot;arrowParens&quot;: &quot;always&quot;,<br>  &quot;bracketSameLine&quot;: false,<br>  &quot;bracketSpacing&quot;: true,<br>  &quot;embeddedLanguageFormatting&quot;: &quot;auto&quot;,<br>  &quot;htmlWhitespaceSensitivity&quot;: &quot;css&quot;,<br>  &quot;insertPragma&quot;: false,<br>  &quot;jsxSingleQuote&quot;: false,<br>  &quot;printWidth&quot;: 80,<br>  &quot;proseWrap&quot;: &quot;preserve&quot;,<br>  &quot;quoteProps&quot;: &quot;as-needed&quot;,<br>  &quot;requirePragma&quot;: false,<br>  &quot;semi&quot;: true,<br>  &quot;singleAttributePerLine&quot;: false,<br>  &quot;singleQuote&quot;: false,<br>  &quot;tabWidth&quot;: 2,<br>  &quot;trailingComma&quot;: &quot;es5&quot;,<br>  &quot;useTabs&quot;: false,<br>  &quot;vueIndentScriptAndStyle&quot;: false<br>}</pre><h3>Class Component Without State or Lifecycle Methods in React</h3><p><em>Original code:</em></p><pre>import React, { Component } from &quot;react&quot;;<br><br>class Adventure extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.handleClick = this.handleClick.bind(this);<br>  }<br><br>  handleClick() {<br>    console.log(&quot;Migration happened&quot;);<br>  }<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>        &lt;button onClick={this.handleClick}&gt;Migrate me&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p><em>Refactored code:</em></p><pre>import React from &quot;react&quot;;<br><br>function Adventure() {<br>  const handleClick = () =&gt; {<br>    console.log(&quot;Migration happened&quot;);<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>      &lt;button onClick={handleClick}&gt;Migrate me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>If the component needs state or <a href="https://reactjs.org/docs/react-component.html#the-component-lifecycle">lifecycle methods</a> then use class component otherwise use function component.</p><p>From <strong>React 16.8</strong> with the addition of <a href="https://reactjs.org/docs/hooks-intro.html">Hooks</a>, you could use state, lifecycle methods and other features that were only available in class component right in your function component. So, it is always recommended to use Function components, unless you need a React functionality whose Function component equivalent is not present yet, like Error Boundaries.</p><h3>Avoid extra wrapping &lt;div&gt; in React</h3><p><em>Original code:</em></p><pre>import React from &quot;react&quot;;<br><br>function Adventure() {<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><em>Refactored code:</em></p><pre>import React, { Fragment } from &quot;react&quot;;<br><br>function Adventure() {<br>  return (<br>    &lt;Fragment&gt;{/* or use a shorter syntax &lt;&gt; &lt;/&gt; */}<br>      &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/Fragment&gt;<br>  );<br>}</pre><p>It’s a common pattern in React which is used for a component to return multiple elements. <a href="https://reactjs.org/docs/fragments.html">Fragments</a> let you group a list of children without adding extra nodes to the DOM.</p><p><em>Why fragments are better than container </em><em>divs?</em></p><ul><li>Fragments are a bit faster and use less memory by not creating an extra DOM node. This only has a real benefit on very large and deep trees.</li><li>Some CSS mechanisms like Flexbox and CSS Grid have a special parent-child relationships and adding divs in the middle makes it hard to keep the desired layout.</li></ul><h3>Naming Conventions</h3><p>Naming is a important part of writing clean and maintainable code and it’s required to take the time to choose descriptive and meaningful names for your <strong>functions</strong> and <strong>variables</strong>. When naming functions and variables, it’s important to choose names that are self explanatory and convey the purpose and function of the code.</p><p>For React, a component name should always be in a Pascal case like UserDashboard, Dashboard etc.. Using Pascal case for components differentiate it from default JSX element tags.</p><p>Methods/functions defined inside components should be in Camel case like getUserData(), showUserData() etc.</p><p>For globally used Constant fields in the application, try to use capital letters only. As an instance,</p><pre>const PI = 3.14;</pre><h3>Remove Unnecessary Comments from the Code</h3><p><em>Original code:</em></p><pre>import React, { Fragment } from &quot;react&quot;;<br><br>function Adventure() {<br>  console.log(&quot;test&quot;);<br>  return (<br>    &lt;Fragment&gt;<br>      {/* &lt;h1&gt;Adventure&lt;/h1&gt; */}<br>      &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/Fragment&gt;<br>  );<br>}</pre><p><em>Refactored code:</em></p><pre>import React from &quot;react&quot;;<br><br>function Adventure() {<br>  return (<br>    &lt;&gt;<br>      &lt;p&gt;Break on Through To the Other Side&lt;/p&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Add comments only where it’s required so that you do not get confused while changing code at a later time.</p><p>Also don’t forget to remove statements like console.log, debugger, unused commented code.</p><h3>Destructuring Props in React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*NncZv5jlXuaAyEMT.png" /><figcaption>Destructuring Props in React</figcaption></figure><p><em>Original code:</em></p><pre>function Adventure(props) {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Hello, {props.username}&lt;/h1&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p><em>Refactored code:</em></p><pre>function Adventure({ username }) {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Hello, {username}&lt;/h1&gt;<br>      &lt;button&gt;Migrate me&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Destructuring was introduced in <a href="https://www.freecodecamp.org/news/write-less-do-more-with-javascript-es6-5fd4a8e50ee2">ES6</a>. This type of feature in the JavaScript function allows you to easily extract the form data and assign your variables from the object or array. Also, destructuring props make code cleaner and easier to read.</p><h3>Respecting the Import Order</h3><p><em>Original code:</em></p><pre>import { formatCurrency, toNumber } from &quot;@/utils&quot;;<br>import { useDrag } from &quot;react-dnd&quot;;<br><br>import &quot;./styleB.css&quot;;<br>import { useFormik } from &quot;formik&quot;;<br>import React, { useEffect, useState } from &quot;react&quot;;<br>import Button from &quot;@/components/Button&quot;;<br>import TextField from &quot;@/components/TextField&quot;;<br>import PropTypes from &#39;prop-types&#39;;</pre><p><em>Refactored code:</em></p><pre>import React, { useEffect, useState } from &quot;react&quot;;<br>import PropTypes from &#39;prop-types&#39;;<br><br>import { useDrag } from &quot;react-dnd&quot;;<br>import { useFormik } from &quot;formik&quot;;<br><br>import { formatCurrency, toNumber } from &quot;@/utils&quot;;<br><br>import Button from &quot;@/components/Button&quot;;<br>import TextField from &quot;@/components/TextField&quot;;<br><br>import &quot;./styleB.css&quot;;</pre><p>Organizing imports is a required part of writing clean and maintainable React code.</p><p><em>Import orders:</em></p><ol><li>React import</li><li>Library imports (Alphabetical order)</li><li>Absolute imports from the project (Alphabetical order)</li><li>Relative imports (Alphabetical order)</li><li>Import * as</li><li>Import ‘./.</li></ol><p>Each kind should be separated by an empty line. This makes your imports clean and easy to understand for all the components, 3rd-party libraries and etc.</p><h3>Split your code into multiple smaller functions. Each with a single responsibility.</h3><p>One of the key principles of writing clean and maintainable code is to keep functions and components small and focused. This means splitting your code into multiple smaller functions, each with a single responsibility.</p><p>When a function or component has too many responsibilities, it becomes harder to read, understand and maintain. By breaking it down into smaller, more focused functions, you can improve the readability and maintainability of your code.</p><p><em>To show you what I mean:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qQohal18fatiEsMo.png" /><figcaption>Split your code into multiple smaller functions. Each with a single responsibility</figcaption></figure><h3>Don’t Repeat Yourself</h3><p><strong>Don’t Repeat Yourself (DRY)</strong> is a fundamental principle of software development. Which encourages developers to avoid duplicating code or logic throughout their codebase. The DRY principle is a required aspect of writing maintainable and scalable code and it applies to both coding standards and code refactoring.</p><p>In terms of coding standards, the DRY principle suggests that you should avoid duplicating code or logic in your codebase. This means that you should strive to write reusable code that can be used in multiple places in your application. As an instance, instead of writing the same validation logic for every input field in your application, you could write a reusable function that performs the validation and use it in each input field.</p><h3>It’s Highly Recommended to Avoid Arrow Functions in Render</h3><p>One way to improve the performance of your components is to avoid using arrow functions in the render() method.</p><p>What’s the problem with below instance?<br>Every time a component is rendered, a new instance of the function is created. Actually, it’s not a big deal in case the component is rendered one or two times. But in other cases, it can affect performance. Arrow functions in the render() method can cause unnecessary re renders of your components.</p><p><em>Original code:</em></p><pre>function Adventure() {<br>  const [message, setMessage] = useState(&quot;Migration not started&quot;);<br><br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Mesage: {message}&lt;/h1&gt;<br>      &lt;button onClick={() =&gt; setMessage(&quot;Migration happened&quot;)}&gt;<br>        Migrate me<br>      &lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>So if you care about performance, declare the function before using it in render as below instance:</p><p><em>Refactored code:</em></p><pre>function Adventure() {<br>  const [message, setMessage] = useState(&quot;Migration not started&quot;);<br>  const onMessage = () =&gt; {<br>    setMessage(&quot;Migration happened&quot;);<br>  };<br>  <br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Mesage: {message}&lt;/h1&gt;<br>      &lt;button onClick={onMessage}&gt;Migrate me&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Instead of using arrow functions in the render() method, you can declare methods as instance methods outside of the render() method. This ensures that the method is only created once and is not recreated on each render.</p><h3>Decrease React Bundle Size</h3><p>When you’re using third-party libraries in your React app, it’s very important to keep the bundle size as small as possible. A large bundle size can negatively impact the performance of your application, especially on slower internet connections.</p><p>One way to reduce the bundle size is to only load the parts of the library that you actually need. Instead of importing the entire library, you can import only the specific method that you need using a technique called <em>tree shaking</em>. This can significantly reduce the size of your bundle.</p><p>Let’s say you’re using the popular library <a href="https://lodash.com/">Lodash</a> and you only need the pick() method to pick certain properties from an object. Instead of importing the entire Lodash library, you can import only the pick() method as below:</p><pre>import pick from &#39;lodash/pick&#39;;<br><br>const pickedUserProps = pick(userProps, [&#39;name&#39;, &#39;email&#39;]);</pre><p>instead of</p><pre>import lodash form &#39;lodash&#39;;<br><br>const pickedUserProps = lodash.pick(userProps, [&#39;name&#39;, &#39;email&#39;]);</pre><h3>Use useMemo to cache expensive calculations</h3><p>When building a React app, it’s common to perform calculations or generate data that can be computationally expensive. This can negatively impact the performance of your app, especially if these calculations are performed frequently or in large amounts.</p><p>To kill the performance issues of your app, you can use the <a href="https://beta.reactjs.org/reference/react/useMemo">useMemo</a> hook in React to cache expensive calculations. useMemo is a built in React hook that memoizes the result of a function, so that it is only recomputed when its dependencies have changed.</p><p>Let’s say you have a component that generates a list of items based on some data that is fetched from an API. The list is generated using a function that performs some expensive calculations:</p><pre>function generateList(data) {<br>  // Perform some expensive calculations here<br>  // ...<br>  return list;<br>}<br><br>function Adventure() {<br>  const [data, setData] = useState([]);<br>  <br>  useEffect(() =&gt; {<br>    // Fetch data from API<br>    // ...<br>    setData(data);<br>  }, []);<br><br>  const list = generateList(data);<br><br>  return (<br>    &lt;ul&gt;<br>      {list.map((item) =&gt; (<br>        &lt;li key={item.id}&gt;{item.name}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><p>With the above instance, the generateList function is called every time the component re-renders, even if the data hasn&#39;t changed. This can result in unnecessary computations and slow down the performance of your application.</p><p>To optimize this, you can use the useMemo hook to cache the result of generateList:</p><pre>function Adventure() {<br>  const [data, setData] = useState([]);<br><br>  useEffect(() =&gt; {<br>    // Fetch data from API<br>    // ...<br>    setData(data);<br>  }, []);<br>  <br>  const list = useMemo(() =&gt; generateList(data), [data]);<br>  // ...<br>}</pre><h3>Remove too many if-else conditions</h3><p>If-else statements are a common feature in most programming languages and they are often used to control the flow of code execution based on certain conditions. Though, too many if-else statements can make your code difficult to read, maintain and debug..</p><p>One approach to removing too many if-else conditions is to use the “switch” statement. The switch statement is similar to an if-else statement, but it is designed to handle multiple cases in a more concise and efficient way. Let’s see an instance:</p><pre>function checkGrade(grade) {<br>  if (grade &gt;= 90) {<br>    return &quot;A&quot;;<br>  } else if (grade &gt;= 80) {<br>    return &quot;B&quot;;<br>  } else if (grade &gt;= 70) {<br>    return &quot;C&quot;;<br>  } else if (grade &gt;= 60) {<br>    return &quot;D&quot;;<br>  } else {<br>    return &quot;F&quot;;<br>  }<br>}</pre><p>In above instance, we are using an if-else statement to check the grade of a student and return a letter grade. This code can be refactored using the switch statement:</p><pre>function checkGrade(grade) {<br>  switch (true) {<br>    case (grade &gt;= 90):<br>      return &quot;A&quot;;<br>    case (grade &gt;= 80):<br>      return &quot;B&quot;;<br>    case (grade &gt;= 70):<br>      return &quot;C&quot;;<br>    case (grade &gt;= 60):<br>      return &quot;D&quot;;<br>    default:<br>      return &quot;F&quot;;<br>  }<br>}</pre><p>As you can see, the switch statement is more concise and easier to read than the if-else statement. It also allows us to handle multiple cases in a more efficient way.</p><p>Another approach to removing too many if-else conditions is to use object literals. Object literals are a way of defining key and value pairs in JavaScript.</p><p><em>To show you what I mean:</em></p><pre>function getAnimalSound(animal) {<br>  if (animal === &quot;dog&quot;) {<br>    return &quot;woof&quot;;<br>  } else if (animal === &quot;cat&quot;) {<br>    return &quot;meow&quot;;<br>  } else if (animal === &quot;cow&quot;) {<br>    return &quot;moo&quot;;<br>  } else {<br>    return &quot;unknown&quot;;<br>  }<br>}</pre><p>In above instance, we are using an if-else statement to return the sound of an animal. This code can be refactored using object literals:</p><pre>function getAnimalSound(animal) {<br>  const animalSounds = {<br>    dog: &quot;woof&quot;,<br>    cat: &quot;meow&quot;,<br>    cow: &quot;moo&quot;<br>  }<br>  return animalSounds[animal] || &quot;unknown&quot;;<br>}</pre><p>As you can see, the object literals approach is more concise and easier to read than the if-else and switch statement. It also allows us to define key and value pairs in a more flexible way..</p><h3>End of an adventure</h3><p>Code refactoring is all about breaking through the limitations of your current code and pushing towards a better, more efficient and effective version. It can be a daunting task, but with the right mindset, tools and best practices, you can take your code to the Other Side.</p><p>Code refactoring is not just about improving the quality of your code, but also about improving the overall user experience of your app. By putting in the effort to refactor your code, you can create a more responsive, intuitive and engaging app that users will love.</p><p>So, don’t be afraid to break through to the other side. Hug the process of code refactoring and watch as your app rises to new heights..</p><h3>Motivation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*LOlqAQdZquOnBoYs.gif" /><figcaption>Motivation</figcaption></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*wpTaaby0ZcSrrLeEOMbWmA.gif" /><figcaption>Thank you in advance for your support!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12368872deb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the javascript:void(0) Statement]]></title>
            <link>https://medium.com/@codeofrelevancy/understanding-the-javascript-void-0-statement-ff4f7d4c14d6?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff4f7d4c14d6</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 14:04:14 GMT</pubDate>
            <atom:updated>2023-02-28T14:04:14.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xlKf6EEdDv9Vfpk5bywC9w.jpeg" /></figure><p>Occasionally, you may come across an HTML document that includes the use of href=&quot;JavaScript:void(0);&quot; within an &lt;a&gt; element. This usage of JavaScript void is often employed when inserting expressions into a web page may result in undesired side effects.</p><p>You can effectively eliminate these negative outcomes as it returns the undefined primitive value.</p><p>A frequent use case for JavaScript:void(0) is with hyperlinks. When you need to call JavaScript within a link, clicking the link typically causes the browser to either load a new page or refresh the current page or lost the current scroll position. But, if you have attached some JavaScript to the link, you may not want this behavior to occur.</p><h3>JavaScript:</h3><p>javascript: is a pseudo URL. A way to embed JavaScript code directly into an HTML document. It can be used as the value of a hyperlink&#39;s href attribute or as the value of an event handler such as onclick.</p><p>For example, if you have a link that needs to perform a specific JavaScript function when clicked, instead of navigating to a different page, you can use the javascript: pseudo URL:</p><pre>&lt;a href=&quot;javascript:myFunction()&quot;&gt;Click here&lt;/a&gt;</pre><p>When the user clicks on the link, the JavaScript function myFunction() will be executed and the page will not navigate away.</p><pre>&lt;a href=&quot;javascript:console.log(&#39;Code of Relevancy&#39;);&quot;&gt;Click me&lt;/a&gt;</pre><p>It is important to note that this method can be a security risk as it allows for potentially malicious code to be executed on the user’s computer, so it should be used with caution.</p><h3>void(0)</h3><p>The void operator is a valuable tool in JavaScript that evaluates an expression and returns the undefined value. It is frequently used to simply obtain the undefined primitive value by using void(0) or void 0. Even, it&#39;s worth noting that the global variable undefined can be used as a substitute for the void operator in most cases, provided it has not been reassigned to a non-default value.</p><h3>Examples</h3><pre>&lt;a href=&quot;JavaScript:void(0)&quot;&gt;Click me, nothing will happen&lt;/a&gt;</pre><p>This anchor tag specifies a hyperlink with a javascript:void(0) URL. When clicked, the JavaScript function void is executed, which returns undefined and has no effect on the page. The purpose of using javascript:void(0) as the href value is to prevent the page from refreshing and changing the URL when the link is clicked. It&#39;s often used when a link is desired but no action is needed to happen.</p><pre>&lt;a href=&quot;#section2&quot;&gt;Go to Section 2&lt;/a&gt;</pre><pre>&lt;a href=&quot;#&quot;&gt;Click me&lt;/a&gt;</pre><p>This anchor tag specifies a hyperlink with a URL of #. The # symbol is often used as a <strong>placeholder URL</strong>, and clicking on the link jumps to the top of the page. It&#39;s also used to create an internal link within the same page, allowing the user to jump to a specific section within the page.</p><h3>Conclusion:</h3><p>javascript:void(0) is used as a placeholder URL when a link is needed but no action is desired, while # is used as a placeholder URL to jump to the top of the page or to create internal links within the same page.</p><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff4f7d4c14d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an Ovulation Calculator App with Next.js, TypeScript, Tailwind CSS and useReducer Hook]]></title>
            <link>https://medium.com/@codeofrelevancy/build-an-ovulation-calculator-app-with-next-js-typescript-tailwind-css-and-usereducer-hook-a0b0ae9b4d58?source=rss-d552f1544dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0b0ae9b4d58</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[women]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Code of Relevancy]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 13:56:47 GMT</pubDate>
            <atom:updated>2023-02-28T13:56:47.292Z</atom:updated>
            <content:encoded><![CDATA[<p>We will be showcasing a powerful ovulation calculator app built using <strong>Next.js</strong>, <strong>TypeScript</strong>, <strong>Tailwind CSS</strong> and the <strong>useReducer</strong> Hook. This app is designed to help women pinpoint their most fertile days by identifying when they are likely ovulating. With this tool you can better understand your own menstrual cycle as it takes into account the varying lengths and dates of periods from person to person.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hV2UaduOrl4tGuZ8DWzLrQ.png" /><figcaption><a href="https://ovulation-calculator.vercel.app/">https://ovulation-calculator.vercel.app</a></figcaption></figure><h3>How to use this app:</h3><p>To use the app simply enter your last period date and cycle length, and the app will automatically calculate your fertile window, ovulation date, next period date, pregnancy test date and expected due date. It’s a simple, yet powerful tool that can help you better understand and track your menstrual cycle. The app is user-friendly and easy to navigate, making it a valuable resource for anyone looking to plan or prevent pregnancy.</p><h3>Tutorial and Basic Source Code:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyskRaxsm2YI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyskRaxsm2YI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyskRaxsm2YI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe54a330cd6c4a586a50c75a0cb237ac/href">https://medium.com/media/fe54a330cd6c4a586a50c75a0cb237ac/href</a></iframe><h3>Learn more about Ovulation Calculator</h3><h3>What is Fertile Window?</h3><p>The fertile window is the period of time during a woman’s menstrual cycle when she is most likely to conceive. This typically occurs in the days leading up to and including ovulation, when an egg is released from the ovary. The fertile window is usually determined by tracking changes in cervical mucus and basal body temperature, and can also be predicted by ovulation predictor kits or fertility tracking apps. It is important to note that the fertile window can vary from woman to woman and cycle to cycle and there is no guaranteed “safe” period for intercourse if a woman wishes to avoid pregnancy.</p><h3>What is Ovulation Date?</h3><p>The ovulation date is the day that a woman releases an egg from her ovary, which is the most fertile time of her menstrual cycle. Ovulation typically occurs around day 14 of a 28-day menstrual cycle, but this can vary depending on the length of a woman’s cycle. Ovulation can be predicted by tracking changes in cervical mucus, basal body temperature, and hormone levels. Ovulation predictor kits and fertility tracking apps can also be used to determine the ovulation date.</p><h3>What is Next Period Date?</h3><p>The next period date is the date on which a woman’s menstrual cycle is expected to begin again. This date is typically calculated based on the length of a woman’s menstrual cycle, which is the number of days from the first day of one period to the first day of the next period. The average menstrual cycle is 28 days, but this can vary from woman to woman and cycle to cycle.</p><p>To calculate the next period date, you can start by identifying the first day of your last period, and then add the number of days in your menstrual cycle. For instance, if your last period began on the 1st of the month and your cycle is 28 days, your next period is expected to begin on the 29th of the same month.</p><h3>What is Pregnancy Test Date?</h3><p>A pregnancy test date is the date on which a woman plans to take a pregnancy test to determine if she is pregnant. This date is typically determined based on the timing of a woman’s menstrual cycle, and the earliest date that a pregnancy test can accurately detect the presence of the pregnancy hormone, <strong>human chorionic gonadotropin (hCG)</strong> in the urine.</p><h3>What is Expected Due Date?</h3><p>The expected due date, also known as the <strong>estimated due date (EDD)</strong>, is the date on which a woman is expected to give birth. This date is typically calculated based on the first day of a woman’s <strong>last menstrual period (LMP)</strong> and is usually calculated as 40 weeks or 280 days from the first day of the LMP. However, only about 5% of women will give birth on their due date, most women give birth within a window of two weeks before or after the due date.</p><h3>Technologies</h3><h3>Next.js:</h3><p>Next.js is a framework that allows for the development of server-rendered React applications, providing a powerful and efficient tool for building web apps. TypeScript, on the other hand, is a superset of JavaScript that adds static typing and other features that make it a great choice for building large-scale applications.</p><h3>Tailwind CSS:</h3><p>The app designed using Tailwind CSS, a utility first CSS framework that makes it easy to build responsive, scalable and consistent interfaces. Tailwind CSS provides a set of pre defined classes that allow developers to quickly and easily create UI elements that are visually consistent across the app.</p><h3>TypeScript:</h3><p>TypeScript is an open source programming language that is a superset of JavaScript. It was developed and is maintained by Microsoft. TypeScript adds optional static typing, class-based object oriented programming and other features to JavaScript. This allows for better code organization, improved developer productivity and more robust code.</p><h3>Code</h3><h3>useReducer hook:</h3><p>The useReducer hook is generally considered to be a better choice when managing complex state in a React application. It allows you to handle state updates in a more centralized and predictable way and also makes it easier to manage updates to state that are dependent on the current state. But, it might be an overkill for small or simple cases, in these cases useState Hook is more than enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*q7RvR_P_GAS36sxs.png" /></figure><h3>useEffect hook:</h3><p>Calculator component uses the useEffect Hook to create a side effect that sets the outcomes when the lastPeriod or cycleLength state values change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*cTWaJ7EMXXI5yHl_.png" /></figure><p>The useEffect Hook takes in a callback function, which is executed when the component is rendered for the first time and subsequently whenever the values of the lastPeriod or cycleLength state variables change.</p><p>The callback function first checks if the lastPeriod or cycleLength state variables have been defined (i.e. not null or undefined) using the logical NOT operator (!). If either of them are not defined the function returns and the effect is not executed.</p><p>Otherwise, the callback function dispatches an action to the outcomes reducer using the dispatchOutcomes function, which is passed as a prop. The action has a type of SET_OUTCOMES and a payload of the result of calling the calculateOutcomes function, which takes in lastPeriod and cycleLength as arguments.</p><p>The second argument of the useEffect Hook is an array of dependencies that the Hook should watch for changes. In this case, it is watching for changes in the lastPeriod and cycleLength state variables, so that the effect is only executed when those values change.</p><h3>Date formatting helper:</h3><p>The toFormatted function takes in a date and an optional formatString as arguments. The formatString defaults to DATE_FORMAT if it is not provided. The function first checks if the date is valid using the isValid function. If the date is not valid, the function returns null. If the date is valid, the function returns the date formatted using the format function of <strong>date-fns</strong> library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*bV1v9aVNCvyZMvbX.png" /></figure><h3>🍀Support</h3><p>Please consider following and supporting us by subscribing to our channel. Your support is greatly appreciated and will help us continue creating content for you to enjoy. Thank you in advance for your support!</p><p><a href="https://youtube.com/@codeofrelevancy">YouTube</a><br><a href="https://github.com/codeofrelevancy">GitHub</a><br><a href="https://twitter.com/codeofrelevancy">Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0b0ae9b4d58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>