<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anagha GN</title>
    <description>The latest articles on DEV Community by Anagha GN (@anagha_gn_e3e7db403e6f6c9).</description>
    <link>https://dev.to/anagha_gn_e3e7db403e6f6c9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1832935%2Fe6e84bc8-dd97-44f9-9e60-091dad416d4d.jpg</url>
      <title>DEV Community: Anagha GN</title>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anagha_gn_e3e7db403e6f6c9"/>
    <language>en</language>
    <item>
      <title>Understanding the Styles of APIs in Vue.js</title>
      <dc:creator>Anagha GN</dc:creator>
      <pubDate>Mon, 13 Jan 2025 11:11:17 +0000</pubDate>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9/understanding-the-styles-of-apis-in-vuejs-21fc</link>
      <guid>https://dev.to/anagha_gn_e3e7db403e6f6c9/understanding-the-styles-of-apis-in-vuejs-21fc</guid>
      <description>&lt;p&gt;Vue is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS, and JavaScript and provides a declarative, component-based programming model that helps you efficiently develop user interfaces of any complexity.&lt;br&gt;
Vue components can be authored in two API styles: Options API and Composition API(Introduced above version 2.6), Both approaches have their unique benefits and drawbacks, and choosing the right one for your project can be a difficult decision.&lt;/p&gt;

&lt;p&gt;Let’s dive deep into both styles of understanding&lt;/p&gt;

&lt;p&gt;Options API:&lt;br&gt;
The Options API is the traditional way of building Vue components. It defines a component's behavior and state using a set of options like data, methods, and computed properties.&lt;br&gt;
data(): This function returns an object containing the component's reactive data properties. These properties will update the component's rendered output when their values change.&lt;br&gt;
methods(): This function returns an object containing methods (functions) that can be used inside the component's template or other methods. These methods can manipulate the data or perform actions.&lt;br&gt;
computed properties: These functions return a value based on the component's data. They are recalculated whenever any of their dependencies (reactive data properties) change.&lt;br&gt;
One of the main benefits of the Options API is that it is simple and easy to understand. It follows a clear, declarative pattern that is familiar to many developers, and it is well-documented in the Vue documentation. This makes it a good choice for beginners who are just starting with Vue.&lt;/p&gt;

&lt;p&gt;However, the Options API has some limitations that can make it difficult to use for more complex projects.&lt;br&gt;
Another limitation of the Options API is that it can be inflexible when it comes to sharing logic between components.&lt;br&gt;
Unit testing components built with the Options API can be more challenging. The spread of logic across different options makes it harder to isolate specific functionalities for testing.&lt;/p&gt;

&lt;p&gt;Let's see the Example of Options API styling :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;h4&amp;gt;{{ name }}'s To Do List&amp;lt;/h4&amp;gt;
        &amp;lt;div&amp;gt;
            &amp;lt;input v-model="newItemText" v-on:keyup.enter="addNewTodo" /&amp;gt;
            &amp;lt;button v-on:click="addNewTodo"&amp;gt;Add&amp;lt;/button&amp;gt;
            &amp;lt;button v-on:click="removeTodo"&amp;gt;Remove&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;ul&amp;gt;
            &amp;lt;li v-for="task in tasks" v-bind:key="task"&amp;gt;{{ task }}&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&amp;lt;script&amp;gt;
    export default { 
    data() { 
           return 
               {  name: "John", 
                  tasks: ["Buy groceries", "Clean the house"], 
                  newItemText: "", 
                };
            }, 
   methods: { 
          addNewTodo() 
            { 
               if (this.newItemText !== "") 
                {  this.tasks.push(this.newItemText); 
                   this.newItemText = ""; 
                } 
            }, 
         removeTodo(index) { this.tasks.splice(index, 1); }, }, };
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Composition API :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Composition API is a set of tools introduced in Vue 3 (and available for Vue 2 through a plugin) that provides an alternative way to write component logic compared to the traditional Options API. It focuses on composing reusable functions to manage a component’s state and behavior.&lt;br&gt;
With Composition API, we define a component’s logic using imported API functions. It also allows developers to use the full power of JavaScript to define component behavior.&lt;br&gt;
Composition API is typically used with . The setup attribute is a hint that makes Vue perform compile-time transforms that allow us to use Composition API with less boilerplate.&amp;lt;br&amp;gt;
The foundation of Composition API is Vue’s built-in reactivity system. Functions like ref and reactive create reactive data that automatically updates the component when it changes. This simplifies state management compared to manually setting up getters and setters in the Options API.&amp;lt;br&amp;gt;
The Composition API supports dependency injection through functions like provide and inject.&amp;lt;br&amp;gt;
The Composition API is particularly beneficial for:&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Building complex and reusable components&amp;lt;br&amp;gt;
Projects that prioritize code organization and maintainability&amp;lt;br&amp;gt;
Applications that leverage TypeScript for type safety&amp;lt;br&amp;gt;
The Composition API may seem like the best option to use. However, the Composition API is not without its drawbacks. One issue is that it can be more difficult to learn for developers who are not familiar with functional, reactive programming.&amp;lt;br&amp;gt;
Another issue is that the Composition API is not backward compatible with Vue 2.6 and under by default. This means you will need to either upgrade to Vue 3.0 or import the Composition API via a plugin.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Let’s see the Example of Composition API styling :&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight plaintext"&amp;gt;&amp;lt;code&amp;gt;&amp;amp;lt;template&amp;amp;gt;
  &amp;amp;lt;div&amp;amp;gt;
    &amp;amp;lt;h4&amp;amp;gt;{{ name }}'s To Do List&amp;amp;lt;/h4&amp;amp;gt;
    &amp;amp;lt;div&amp;amp;gt;
      &amp;amp;lt;input v-model="newItemText" v-on:keyup.enter="addNewTodo" /&amp;amp;gt;
      &amp;amp;lt;button v-on:click="addNewTodo"&amp;amp;gt;Add&amp;amp;lt;/button&amp;amp;gt;
      &amp;amp;lt;button v-on:click="removeTodo"&amp;amp;gt;Remove&amp;amp;lt;/button&amp;amp;gt;
    &amp;amp;lt;/div&amp;amp;gt;
    &amp;amp;lt;ul&amp;amp;gt;
      &amp;amp;lt;li v-for="task in tasks" v-bind:key="task"&amp;amp;gt;{{ task }}&amp;amp;lt;/li&amp;amp;gt;
    &amp;amp;lt;/ul&amp;amp;gt;
  &amp;amp;lt;/div&amp;amp;gt;
&amp;amp;lt;/template&amp;amp;gt;

&amp;amp;lt;script&amp;amp;gt;
import { ref } from 'vue';

export default {
  setup() {
    const name = ref('John');
    const tasks = ref(['Buy groceries', 'Clean the house']);
    const newItemText = ref('');

    const addNewTodo = () =&amp;amp;gt; {
      if (newItemText.value !== '') {
        tasks.value.push(newItemText.value);
        newItemText.value = '';
      }
    };

    const removeTodo = (index) =&amp;amp;gt; {
      tasks.value.splice(index, 1);
    };

    return { name, tasks, newItemText, addNewTodo, removeTodo };
  },
};
&amp;amp;lt;/script&amp;amp;gt;
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Here we import ref from Vue to create reactive data. The setup function replaces the data and methods options from the Options API. We create reactive references for name, tasks, and newItemText using ref.The addNewTodo and removeTodo functions are defined inside setup and manage the state changes. The setup function returns an object containing the reactive data and functions, making them accessible in the template.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;I hope you found the article Insightful, we explored the differences between these two approaches, highlighting their respective advantages and disadvantages. This should help you make an informed decision about which API to use in your next Vue project.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Reference :&amp;lt;br&amp;gt;
Vue.js&amp;lt;br&amp;gt;
Options and Compositions API styles&amp;lt;/p&amp;gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>LLM Fundamentals — Hallucinations in LLMs 101 [Part I]</title>
      <dc:creator>Anagha GN</dc:creator>
      <pubDate>Fri, 20 Sep 2024 06:05:23 +0000</pubDate>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9/llm-fundamentals-hallucinations-in-llms-101-part-i-2k4e</link>
      <guid>https://dev.to/anagha_gn_e3e7db403e6f6c9/llm-fundamentals-hallucinations-in-llms-101-part-i-2k4e</guid>
      <description>&lt;p&gt;Def: A hallucination is a perception in the absence of an external stimulus that has a compelling sense of reality (Ref: Wiki).&lt;/p&gt;

&lt;p&gt;In simple terms, a hallucination is an unreal perception that feels real.&lt;/p&gt;

&lt;p&gt;For human beings — Hallucination traces its roots in the fields of pathology and psychology. It is defined as a set of experiences where a person perceives something that isn’t actually present. In human beings, hallucinations can affect any of the senses, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Auditory hallucinations:&lt;/strong&gt; Hearing sounds, voices, or noises that aren’t there&lt;br&gt;
&lt;strong&gt;Visual hallucinations:&lt;/strong&gt; Seeing things that aren’t actually present, such as objects or people&lt;br&gt;
&lt;strong&gt;Olfactory hallucinations:&lt;/strong&gt; Smelling odours that have no external source&lt;br&gt;
&lt;strong&gt;Gustatory hallucinations:&lt;/strong&gt; Tasting flavours that aren’t actually present.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2d6olqjjdyi8ft1zv96n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2d6olqjjdyi8ft1zv96n.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hallucinations can be caused by a range of factors, including mental health conditions, neurological disorders, substance abuse, or extreme stress and fatigue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hallucinations in LLM&lt;/strong&gt;&lt;br&gt;
The emergence of LLMs and their wide-scale adoption in recent years has opened innumerable opportunities to integrate AI/ML seamlessly into technology products across domains. However, while doing so it has become imperative to understand Hallucinations in LLMs and the impact it has on the adoption of LLMs in live technology platforms wrt the reliability of the output that the LLM systems generate.&lt;/p&gt;

&lt;p&gt;Within the realm of (Natural Language Processing (NLP), hallucination is typically referred to as a phenomenon in which the generated content appears nonsensical or unfaithful to the provided source content (Filippova, 2020; Maynez et al., 2020).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumu23xvqosskra0d35zv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumu23xvqosskra0d35zv.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LLM Hallucination — Ref #2 (A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions Huang et al.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Categorization of Hallucination in LLMs&lt;/strong&gt;&lt;br&gt;
Initially, LLM Hallucinations were categorized into 2 types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intrinsic Hallucinations:&lt;/strong&gt; The output generated by the LLM that contradicts the source content. For instance, in the abstractive summarization in the below example, the generated summary “The first Ebola vaccine was approved in 2021” contradicts the source content “The first vaccine for Ebola was approved by the FDA in 2019.”&lt;br&gt;
Extrinsic Hallucinations: The output generated by the LLM cannot be verified from the source content (i.e., output that can neither be supported nor contradicted by the source). For example, in the abstractive summarization task in the below example, the information “China has already started clinical trials of the COVID-19 vaccine.” is not mentioned in the source. We can neither find evidence for the generated output from the source nor assert that it is wrong. Notably, extrinsic hallucination is not always erroneous because it could be from factually correct external information. Such factual hallucination can be helpful because it recalls additional background knowledge to improve the informativeness of the generated text. However, in most of the literature, extrinsic hallucination is still treated with caution because its unverifiable aspect of this additional information increases the risk from a factual safety perspective.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7ou52hh2qmjcm73r1hy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7ou52hh2qmjcm73r1hy.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
Abstractive Summarization — Ref #1 (Survey of Hallucination in Natural Language Generation — Ji et al.)&lt;/p&gt;

&lt;p&gt;In recent times, the LLMs emphasize user-centric interactions, and their hallucinations appear at factual levels. Taking this into consideration Huang et al. in their paper “A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions” introduced a more granular hallucination taxonomy as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk3ookl9tydwp1s86qhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk3ookl9tydwp1s86qhw.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
Categories of Hallucinations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Factual Hallucination&lt;/strong&gt;**&lt;br&gt;
Existing LLMs frequently manifest tendencies to produce results that are either inconsistent with real-world facts or are most likely misleading. This poses a challenge to the trustworthiness of artificial intelligence. In such a context, such factual errors are classified as factuality hallucinations.&lt;/p&gt;

&lt;p&gt;Depending on whether the generated factual content can be verified against a reliable source, they can be further divided into two primary types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Factual Inconsistency&lt;/strong&gt; — It refers to situations where the LLM’s output contains facts that can be grounded in real-world information, but present contradictions. This type of hallucination occurs most frequently and arises from diverse sources, encompassing the LLM’s capture, storage, and expression of factual knowledge. As shown in the below example, when inquired about “the first person to land on the Moon”, the model erroneously generated “Yuri Gagarin”, which contradicts the real-world fact.&lt;/p&gt;

&lt;p&gt;Factual Fabrication — Here the LLM’s output contains facts that are unverifiable against established real-world knowledge. As demonstrated in the below example, while “the origins of unicorns” traditionally lack empirical grounding, the model fabricated a plausible historical origin for unicorns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4agijh0di9ed0sb0dvg0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4agijh0di9ed0sb0dvg0.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Types of Factual Hallucinations&lt;/strong&gt; — Ref #2 (A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions Huang et al.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Faithfulness Hallucination&lt;/strong&gt;&lt;br&gt;
LLMs by default are trained to align with the instructions given by the user. As the use of LLMs shifts towards more user-centric applications, ensuring their consistency with user-provided instructions and contextual information becomes crucial. Moreover, LLM’s faithfulness is also reflected in the logical consistency of its generated content. From this perspective, Huang et al. categorize three subtypes of faithfulness hallucinations:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Instruction inconsistency *&lt;/em&gt;— In this type of hallucination the LLM’s outputs deviate from a user’s directive. While some deviations might serve safety guidelines, the inconsistencies here signify unintentional misalignment with non-malicious user instructions. As shown in the below example, the user’s actual intention is translation, However, the LLM erroneously deviated from the user’s instruction and performed a question-answering task instead.&lt;br&gt;
Context inconsistency — These are the hallucinations where the LLM’s output is not consistent/faithful with the user’s provided contextual information. As shown in the below example, the user mentioned the Nile’s source being in the Great Lakes region of central Africa, yet the LLM’s response contradicted the context.&lt;br&gt;
Logical inconsistency — In this type of hallucination the LLM outputs reveal internal logical contradictions, especially observed in their reasoning tasks. As a result, inconsistencies appear both among the reasoning steps themselves and between the steps and the final answer. As shown in the below example, while the reasoning step of dividing both sides of the equation by 2 is correct, the final answer of x=4 is inconsistent with the reasoning chain, leading to an incorrect result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fve0uvdsqpk6k7pzplxc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fve0uvdsqpk6k7pzplxc1.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Types of Faithfulness Hallucinations&lt;/strong&gt; — Ref #2 (A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions Huang et al.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;br&gt;
Survey of Hallucination in Natural Language Generation — Ji, Ziwei and Lee, Nayeon and Frieske, Rita and Yu, Tiezheng and Su, Dan and Xu, Yan and Ishii, Etsuko and Bang, Ye Jin and Madotto, Andrea and Fung, Pascale&lt;br&gt;
A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questions — Lei Huang and Weijiang Yu and Weitao Ma and Weihong Zhong and Zhangyin Feng and Haotian Wang and Qianglong Chen and Weihua Peng and Xiaocheng Feng and Bing Qin and Ting Liu&lt;br&gt;
Note: Significant content of this tech blog has strong references from the above 2 papers.&lt;/p&gt;

&lt;p&gt;In our next blog, we will dive deep into the key aspects contributing to hallucinations in LLMs. Stay tuned 💡&lt;/p&gt;

</description>
      <category>llm</category>
      <category>ai</category>
    </item>
    <item>
      <title>From Fish to Flying Dogs: Vivek’s Playful Guide to SOLID Principles with Tara at NonStop</title>
      <dc:creator>Anagha GN</dc:creator>
      <pubDate>Wed, 07 Aug 2024 11:18:10 +0000</pubDate>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9/from-fish-to-flying-dogs-viveks-playful-guide-to-solid-principles-with-tara-at-nonstop-bhc</link>
      <guid>https://dev.to/anagha_gn_e3e7db403e6f6c9/from-fish-to-flying-dogs-viveks-playful-guide-to-solid-principles-with-tara-at-nonstop-bhc</guid>
      <description>&lt;p&gt;Scene: Tara, a new Intern, has just joined NonStop IO Technologies Pvt. Ltd. She’s eager to learn about best coding practices. Vivek, the Project Manager, decides to explain the SOLID principles to her using the context of aquatic and terrestrial animals. They are sitting in the company lounge with a cup of coffee.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (smiling) Welcome to NonStop IO Technologies, Tara! How’s your first day going?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tara:&lt;/strong&gt; (grinning) It’s been great so far, Vivek. Just trying to soak in all the new information. By the way, I’ve been hearing a lot about these SOLID principles. What’s all the hype about?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (chuckling) Ah, the famous SOLID principles! They’re like the Avengers of software design — each one has its superpower to save us from bad code. Let’s start with the Single Responsibility Principle, or SRP. Imagine a Zoo class that handles feeding, entertaining, and displaying animals. It’s like asking a fish to swim, walk, and fly. Impossible, right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tara:&lt;/strong&gt; (laughing) I’d love to see a flying fish, though!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (laughs) True! But in coding terms, it’s a mess. Here’s an example of how the Zoo class violates SRP:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Violation Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Zoo {
  void feedAnimals() {
    print('Feeding animals');
    // Code to feed animals
  }
  void entertainAnimals() {
    print('Entertaining animals');
    // Code to entertain animals
    Fish fish = Fish();
    fish.swim();
    Bird bird = Bird();
    bird.fly();
    bird.walk();
    Dog dog = Dog();
    dog.walk();
    dog.swim();
  }
void displayAnimals() {
    print('Displaying animals');
    // Code to display animals to visitors
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The Zoo class handles multiple responsibilities: feeding animals, entertaining them, and displaying them. This violates SRP because changing one responsibility (e.g., how animals are entertained) would require modifying the Zoo class, making it more complex and error-prone.&lt;br&gt;
&lt;strong&gt;Correction Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Feeder {
  void feedAnimals() {
    print('Feeding animals');
    // Code to feed animals
  }
}
class Entertainer {
  void entertainAnimals() {
    print('Entertaining animals');
    // Code to entertain animals
    Fish fish = Fish();
    fish.swim();
    Bird bird = Bird();
    bird.fly();
    bird.walk();
    Dog dog = Dog();
    dog.walk();
    dog.swim();
  }
}
class Displayer {
  void displayAnimals() {
    print('Displaying animals');
    // Code to display animals to visitors
  }
}
Correction Explanation:

Each class (Feeder, Entertainer, Displayer) now has a single responsibility. This makes the code more modular and easier to maintain.
Tara: Got it! So each class has its responsibility. What’s next?

Vivek: Next up, OCP — the Open/Closed Principle. Classes should be open for extension but closed for modification. Here’s how our Zoo class violates OCP:

Violation Example:

class Zoo {
  void showAnimals() {
    Fish fish = Fish();
    Bird bird = Bird();
    Dog dog = Dog();
    fish.swim();
    bird.fly();
    bird.walk();
    dog.swim();
    dog.walk();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The Zoo class directly depends on specific implementations of Fish, Bird, and Dog. If you want to add a new animal, you’d have to modify the showAnimals method, which violates OCP.&lt;br&gt;
&lt;strong&gt;Correction Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Swimmer {
  void swim();
}
abstract class Walker {
  void walk();
}
abstract class Flyer {
  void fly();
}
class Fish implements Swimmer {
  @override
  void swim() {
    print('Fish is swimming');
  }
}
class Bird implements Walker, Flyer {
  @override
  void fly() {
    print('Bird is flying');
  }
@override
  void walk() {
    print('Bird is walking');
  }
}
class Dog implements Walker, Swimmer {
  @override
  void swim() {
    print('Dog is swimming');
  }
@override
  void walk() {
    print('Dog is walking');
  }
}
class Zoo {
  final List&amp;lt;Swimmer&amp;gt; swimmers;
  final List&amp;lt;Walker&amp;gt; walkers;
  final List&amp;lt;Flyer&amp;gt; flyers;

Zoo(this.swimmers, this.walkers, this.flyers);

void showSwimmers() {
    for (var swimmer in swimmers) {
      swimmer.swim();
    }
  }
void showWalkers() {
    for (var walker in walkers) {
      walker.walk();
    }
  }
void showFlyers() {
    for (var flyer in flyers) {
      flyer.fly();
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Correction Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using interfaces (Swimmer, Walker, Flyer), the Zoo class can work with any new animal that implements these interfaces, adhering to OCP.&lt;br&gt;
&lt;strong&gt;Tara:&lt;/strong&gt; So, no tearing down walls for a new animal? Sounds like a relief for the animals and the developers!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (grinning) Exactly! Now, LSP — Liskov Substitution Principle. This principle ensures that derived classes can substitute base classes without breaking the system. Here’s how it’s violated:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Violation Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Swimmer {
  void swim();
}

class Fish implements Swimmer {
  @override
  void swim() {
    print('Fish is swimming');
  }
}

class Dog implements Swimmer {
  @override
  void swim() {
    print('Dog is swimming');
  }

  void bark() {
    print('Dog is barking');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;In this example, Dog is substituting for Swimmer, but it introduces additional behaviors (bark()) that Fish doesn’t have. This could cause issues when using a Swimmer in a context where only swimming is expected, as Dog introduces unexpected behavior.&lt;br&gt;
*&lt;em&gt;Correction Example:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Swimmer {
  void swim();
}

class Fish implements Swimmer {
  @override
  void swim() {
    print('Fish is swimming');
  }
}

class Dog implements Swimmer {
  @override
  void swim() {
    print('Dog is swimming');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Correction Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both Fish and Dog implement the Swimmer interface correctly, focusing solely on swimming. This adheres to LSP as both classes can be used interchangeably wherever a Swimmer is expected without introducing unexpected behaviors.&lt;br&gt;
This adjustment ensures that the Swimmer interface remains consistent and reliable, adhering to LSP by not introducing additional methods or behaviors that aren’t expected by the base interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tara:&lt;/strong&gt; (giggling) Unless it’s on some sort of superhero potion!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (laughs) Exactly! For superheroes, we have a separate interface. Then, we have ISP — the Interface Segregation Principle. This principle means no client should be forced to depend on interfaces it doesn’t use. Here’s how it’s violated:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Violation Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Animal {
  void swim();
  void walk();
  void fly();
}
class Fish implements Animal {
  @override
  void swim() {
    print('Fish is swimming');
  }
@override
  void walk() {
    throw UnimplementedError(); // Fish can’t walk
  }
@override
  void fly() {
    throw UnimplementedError(); // Fish can’t fly
  }
}
class Bird implements Animal {
  @override
  void swim() {
    throw UnimplementedError(); // Bird can’t swim
  }
@override
  void walk() {
    print('Bird is walking');
  }
@override
  void fly() {
    print('Bird is flying');
  }
}
Explanation:

The Animal interface forces all animals to implement swim, walk, and fly, even if they don’t need those methods. This violates ISP because Fish and Bird are forced to implement methods that don’t apply to them.
Correction Example:

abstract class Swimmer {
  void swim();
}
abstract class Walker {
  void walk();
}
abstract class Flyer {
  void fly();
}
class Fish implements Swimmer {
  @override
  void swim() {
    print('Fish is swimming');
  }
}
class Bird implements Walker, Flyer {
  @override
  void fly() {
    print('Bird is flying');
  }
@override
  void walk() {
    print('Bird is walking');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Correction Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using separate interfaces (Swimmer, Walker, Flyer), each animal class only implements the methods it needs. This adheres to ISP by ensuring that classes are not burdened with unnecessary methods.&lt;br&gt;
Tara: (laughing) Or making a dog try to fly — though, a cape might help!&lt;/p&gt;

&lt;p&gt;Vivek: (chuckling) True, true. And finally, we have DIP — Dependency Inversion Principle. High-level modules shouldn’t depend on low-level modules but on abstractions. Here’s how it’s violated:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Violation Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Zoo {
  void showAnimals() {
    Fish fish = Fish();
    Bird bird = Bird();
    Dog dog = Dog();
    fish.swim();
    bird.fly();
    bird.walk();
    dog.swim();
    dog.walk();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;In this design, the Zoo class depends on concrete implementations (Fish, Bird, Dog). If we want to change the behavior or add new animal types, we need to modify the Zoo class, which violates DIP.&lt;br&gt;
&lt;strong&gt;Correction Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Swimmer {
  void swim();
}

abstract class Walker {
  void walk();
}

abstract class Flyer {
  void fly();
}

class Fish implements Swimmer {
  @override
  void swim() {
    print('Fish is swimming');
  }
}

class Bird implements Walker, Flyer {
  @override
  void fly() {
    print('Bird is flying');
  }

  @override
  void walk() {
    print('Bird is walking');
  }
}

class Dog implements Walker, Swimmer {
  @override
  void swim() {
    print('Dog is swimming');
  }

  @override
  void walk() {
    print('Dog is walking');
  }
}

class Zoo {
  final Swimmer swimmer;
  final Walker walker;
  final Flyer flyer;

  Zoo(this.swimmer, this.walker, this.flyer);

  void performShow() {
    swimmer.swim();
    walker.walk();
    flyer.fly();
  }
}

void main() {
  Zoo zoo = Zoo(Fish(), Dog(), Bird());
  zoo.performShow();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Correction Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We define Swimmer, Walker, and Flyer interfaces as abstractions. Fish, Bird, and Dog implement these interfaces as low-level modules. The Zoo class depends on these abstractions (Swimmer, Walker, Flyer) rather than concrete implementations.&lt;br&gt;
Now, the Zoo class is not tightly coupled to specific animal classes. We can easily swap out different implementations (e.g., replace Dog with a Cat that implements Walker) without changing the Zoo class. This design adheres to the Dependency Inversion Principle, promoting flexibility and maintainability.&lt;br&gt;
Tara: So, the pet-sitter is prepared for anything — from fish to flying birds?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (grinning) Exactly! It’s about being adaptable and prepared for change. And that, my dear intern, is a quick tour through the SOLID zoo!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tara:&lt;/strong&gt; (smiling) That was fun and enlightening! Now I can brag about understanding SOLID principles to my friends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (laughing) You sure can! And remember, this is just the beginning. At NonStop IO Technologies Pvt. Ltd., we’re all about quality code and having fun while learning. You’ll get the best mentoring and training here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tara:&lt;/strong&gt; (grateful) I can already see that. Thanks for the awesome explanation, Vivek! I’m looking forward to learning more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vivek:&lt;/strong&gt; (smiling) Anytime, Tara! Welcome aboard, and remember, we’re all in this together — whether you’re a dog, bird, or even a flying fish! 😊&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Conclusion: Understanding and applying SOLID principles helps create a more flexible, maintainable, and scalable codebase. At NonStop IO Technologies Pvt. Ltd., we take pride in providing top-notch mentoring and training to ensure our developers can apply these principles effectively, making our software as robust and adaptable as a well-tended zoo.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>solidprinciples</category>
      <category>development</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Portals Explained: A Guide for Developers</title>
      <dc:creator>Anagha GN</dc:creator>
      <pubDate>Fri, 26 Jul 2024 08:20:55 +0000</pubDate>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9/unleashing-the-power-of-vyuh-building-scalable-flutter-apps-with-ease-2bg4</link>
      <guid>https://dev.to/anagha_gn_e3e7db403e6f6c9/unleashing-the-power-of-vyuh-building-scalable-flutter-apps-with-ease-2bg4</guid>
      <description>&lt;p&gt;React Portals provide an advanced capability in React, enabling developers to render components outside the main React component hierarchy. This functionality is particularly useful for creating modals, tooltips, and other elements that need to exist outside their parent component’s DOM structure. By leveraging portals, developers can achieve more flexible and robust user interface designs, enhancing the overall user experience.&lt;/p&gt;

&lt;p&gt;In this article, we will delve into React Portals, examining their functionality and demonstrating how to utilize them effectively within your React applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction to React Portals&lt;/strong&gt;&lt;br&gt;
React Portals offer a solution for rendering components into a DOM node that exists outside the usual component hierarchy. Typically, rendering a component in React inserts it as a child within its parent component’s DOM structure. However, there are cases, such as creating modals or dropdown menus, where it is necessary to render a component elsewhere in the DOM.&lt;/p&gt;

&lt;p&gt;React Portals address this by allowing a component’s output to be rendered in a different DOM node, outside of its parent component’s DOM hierarchy. This approach enables the visual display of components at any location within the DOM while maintaining their logical position in the React component tree.&lt;/p&gt;

&lt;p&gt;This functionality is made possible by a feature in react-dom called “portals.” The react-dom library provides a createPortal method, which takes two arguments: the content to be rendered (referred to as children) and the target DOM node where the content should be rendered, as demonstrated below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`import {createPortal} from 'react-dom';
createPortal(children, domNodeContainer);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some use cases for React Portals include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Modal Dialogs: Modals often need to overlay the entire page, requiring them to be rendered outside the current component hierarchy to ensure they appear above all other content. React Portals facilitate the rendering of modal components outside their parent components, simplifying the management of their visibility and behavior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tooltips and Popovers: These components usually need to be displayed near a specific element or at a certain position on the page. React Portals allow you to render tooltips and popovers in a different part of the DOM, enabling precise positioning relative to the triggering element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dropdown Menus: To ensure correct positioning and layering, dropdown menus must often be rendered outside their parent component. React Portals make it easy to render dropdown menus outside the regular component hierarchy, while still maintaining their interaction with the triggering elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Benefits of using React Portals&lt;/strong&gt;&lt;br&gt;
React Portals provide several advantages when building React applications, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Versatile Component Placement&lt;/strong&gt;: React Portals enable components to be rendered anywhere in the DOM, outside the usual component hierarchy. This offers greater flexibility for creating complex UIs and precisely positioning components as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Separation of Visual and Logical Concerns&lt;/strong&gt;: Portals allow the visual display of a component to be separated from its logical position in the component tree. This improves code organization and makes the codebase easier to understand and maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Reduced CSS Conflicts&lt;/strong&gt;: By rendering components through portals, their styles are isolated from parent and sibling components. This helps to prevent CSS conflicts, ensuring that the styles of portal components remain unaffected by the surrounding environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Improved Accessibility&lt;/strong&gt;: Portals are particularly useful for creating accessible components, such as modals. By rendering them at the top level of the DOM, they become more accessible to screen readers and assistive technologies, enhancing the overall accessibility of the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Seamless Integration with Third-Party Libraries&lt;/strong&gt;: React Portals make it easier to integrate third-party libraries or components that need to be rendered outside the main React hierarchy. This allows external functionalities to be incorporated seamlessly while maintaining the integrity of the React application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Enhanced Performance&lt;/strong&gt;: React Portals can boost application performance by reducing unnecessary re-renders. Since portal components are rendered outside the regular component hierarchy, they can be updated independently, minimizing the need for re-renders throughout the entire application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to implement React Portals?&lt;/strong&gt;&lt;br&gt;
To illustrate the functionality of React Portals, let’s build an example using a modal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create React application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npm create vite@latest
Need to install the following packages:
create-vite@5.4.0
Ok to proceed? (y) y
✔ Project name: … sample-react-portal
✔ Select a framework: › React
✔ Select a variant: › JavaScript`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we will develop an application component that includes a button element and a modal component. The modal will be displayed only when the button is clicked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`import { useState } from 'react';
import './App.css';
import Modal from './modal.jsx';

function App() {
 const [isOpen, setOpen] = useState(false);
 return (
  &amp;lt;div&amp;gt;
   &amp;lt;button
    onClick={() =&amp;gt; {
     setOpen(true);
    }}&amp;gt;
    Open
   &amp;lt;/button&amp;gt;
   &amp;lt;Modal isOpen={isOpen} onClose={() =&amp;gt; setOpen(false)} /&amp;gt;
  &amp;lt;/div&amp;gt;
 );
}
export default App;`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The provided code defines an App component that includes a button for toggling the visibility of a modal component. The display of the modal is controlled by the isOpen state variable. When the button is clicked, the modal appears. The modal can be closed by invoking the onClose function, which updates the state to hide the modal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;modal.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`import React from 'react';
import { createPortal } from 'react-dom';
import './modal.css';

export default function Modal({ isOpen, onClose }) {
 if (!isOpen) return null;
 return createPortal(
  &amp;lt;div className='modal'&amp;gt;
   &amp;lt;div className='modal-container'&amp;gt;
    &amp;lt;div className='modal-body'&amp;gt;
     &amp;lt;p&amp;gt;Sample Modal&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;button onClick={onClose}&amp;gt;Close&amp;lt;/button&amp;gt;
   &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;,
  document.getElementById('modal') // this instructs `react-dom` to render the modal outside the current React component hierarchy.
 );
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The modal component is designed to accept two props: isOpen and onClose. The isOpen prop determines the visibility of the modal, while the onClose prop is a callback function that gets invoked to close the modal.&lt;/p&gt;

&lt;p&gt;When the isOpen prop is set to false, the modal is not rendered, and the component returns null, meaning no content is displayed.&lt;/p&gt;

&lt;p&gt;When the isOpen prop is true, the component utilizes the createPortal function to render the modal content outside the current React component hierarchy. The createPortal function takes two arguments: the JSX code representing the modal and the target DOM element where the modal should be rendered. In this scenario, the target DOM element is specified as document.getElementById(‘modal’). This instructs react-dom to render the modal within the DOM element with the ID modal, effectively positioning it outside the normal React component tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To proceed, open the index.html file. You’ll find a div element with the ID root. This element serves as the container for all React-rendered content.&lt;/p&gt;

&lt;p&gt;In the main.jsx file (for Vite) or the index.js file (for Create React App), you’ll observe that react-dom references this root element. It constructs a new DOM structure dedicated to React components and renders each component within this structure.&lt;/p&gt;

&lt;p&gt;For our project, modify the index.html file by adding another div element with the ID modal. This will serve as the target for rendering our modal component outside the main React component tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;link rel="icon" type="image/svg+xml" href="/vite.svg" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Sample React Portal&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="modal"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="/src/main.jsx"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;modal.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s apply some basic styling to our modal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;modal.css&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
 color: black;
}
.modal {
 position: fixed;
 z-index: 2;
 top: 0;
 left: 0;
 width: 100%;
 height: 100%;
 background-color: rgba(0, 0, 0, 0.5);
 overflow: auto;
}
.modal-container {
 background-color: #fefffe;
 margin: 10% auto;
 width: 50%;
 padding: 10px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s start the server to view the components in action. Execute the following command and open the URL [&lt;a href="http://127.0.0.1:5173/" rel="noopener noreferrer"&gt;http://127.0.0.1:5173/&lt;/a&gt;] in your browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npm run dev`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv64xsdoasljdux9fayc2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv64xsdoasljdux9fayc2.gif" alt="Image description" width="600" height="318"&gt;&lt;/a&gt;&lt;br&gt;
React Portal Example&lt;/p&gt;

&lt;p&gt;We can see that the button element is rendered within the main root container, representing the primary container for the entire React application. However, the modal component, despite being defined within the parent App component, is rendered in a separate target location in the DOM, typically outside the regular React component tree.&lt;/p&gt;

&lt;p&gt;In our code, the modal component is a child of a div element within the App component, which is centrally located in the root container. React Portals enable us to define the modal component within the App component while rendering it in a different part of the DOM, outside the regular React tree structure. This functionality allows us to pass values to the modal’s props and render content within the modal component effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Considerations and Potential Issues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React Portals offer valuable capabilities, but there are several important factors to consider:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Target DOM Nodes:&lt;/strong&gt; When utilizing portals, ensure the target DOM node exists within the document. If the target node is missing, it can lead to errors or unintended behavior. It is prudent to confirm the presence of the target node before attempting to render portal content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Event Propagation:&lt;/strong&gt; Events emitted from a portal component will, by default, bubble up through the React tree and may trigger event handlers on parent components. This default behavior might not always be desirable. To control event propagation and limit event handling to within the portal, consider using stopPropagation() or other event management techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Styling Challenges:&lt;/strong&gt; Since portal components are rendered outside the standard React component hierarchy, applying CSS can be tricky. Styles that depend on parent-child relationships might not behave as expected. It is advisable to use specific CSS selectors or scoped styling to ensure that portal components are styled correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Performance Considerations:&lt;/strong&gt; React Portals can enhance performance in certain scenarios, but they can also introduce overhead. For instance, rendering a large list of items (e.g., 1,000 entries) through a portal requires two render passes: one for the virtual DOM and another for the actual DOM. This additional rendering step can impact performance, particularly with large amounts of content. To avoid performance issues, use portals selectively and only when necessary.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;React Portals offer a robust solution for rendering components outside their parent component hierarchy, enabling the creation of complex and flexible user interfaces by placing components at any location within the DOM. Utilizing portals can help with separating concerns, enhancing accessibility, and providing greater adaptability in developing React applications.&lt;br&gt;
To ensure effective use and avoid potential pitfalls, it is essential to adhere to the considerations and best practices outlined in this guide. With careful application, React Portals can significantly expand the capabilities of your React applications and improve the overall user experience.&lt;br&gt;
Take advantage of React Portals to craft dynamic, interactive, and visually engaging components in your React projects.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>reactjsdevelopment</category>
      <category>webdevelopement</category>
    </item>
    <item>
      <title>Building Scalable Flutter Apps with Ease</title>
      <dc:creator>Anagha GN</dc:creator>
      <pubDate>Thu, 25 Jul 2024 17:05:55 +0000</pubDate>
      <link>https://dev.to/anagha_gn_e3e7db403e6f6c9/unleashing-the-power-of-vyuh-building-scalable-flutter-apps-with-ease-9of</link>
      <guid>https://dev.to/anagha_gn_e3e7db403e6f6c9/unleashing-the-power-of-vyuh-building-scalable-flutter-apps-with-ease-9of</guid>
      <description>&lt;p&gt;Building large-scale apps with diverse features and large developer teams requires a modular approach. Vyuh is a framework that uses a CMS-driven methodology to create scalable Flutter apps, allowing dynamic updates without App Store/Play Store releases. Born from the need to manage complex, content-driven features efficiently, Vyuh integrates with Sanity.io to drive the entire app experience.&lt;/p&gt;

&lt;p&gt;It balances the flexibility of no-code tools for business teams with the power of full-code IDEs for developers. Vyuh separates responsibilities, enabling business teams to create app journeys through high-level components defined in the CMS, while developers focus on the implementation details in Flutter. This approach ensures modular, transferable features, controlled navigation, and seamless third-party integrations, all supported by a strong design system.&lt;/p&gt;

&lt;p&gt;To get into its deep dive, let see below is a sample conversation that happened between Tara (who is a client and wanted to have the News app to be developed and deployed quickly) and Vivek (who is a Project Manager at NonStop IO Technologies Pvt Ltd) who knows the capability and adaptability of Vyuh framework very well. Below is the screenshot of the home page of their News App.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fneca9enzn8sq8e0nxf4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fneca9enzn8sq8e0nxf4m.png" alt="Image description" width="706" height="1508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Project Manager (Vivek): Hello Tara, our News App has been Developed and Published!&lt;/p&gt;

&lt;p&gt;Client(Tara): (After installing the app) Ahh! Wow really??? in just a week? (After checking the smoothness of the app)…This news app is Good for me!!. Just a few changes need to be made.&lt;/p&gt;

&lt;p&gt;Vivek: yeah, sure! can you tell me which changes?&lt;/p&gt;

&lt;p&gt;Tara: Instead of opening this News/Category Page on a separate page, can we open it from a dialog that will be coming from the bottom??&lt;/p&gt;

&lt;p&gt;Vivek: Umm.. Do you mean BottomSheet, yes we can open it.&lt;/p&gt;

&lt;p&gt;Tara: But Vivek, it will again take a day to make this change and then publish and then review. How hectic the process is! Isn’t it?&lt;/p&gt;

&lt;p&gt;Vivek: But Tara, We can do it instantly, you just have to refresh your app&lt;/p&gt;

&lt;p&gt;Tara: (Surprisingly) What?? are you joking??&lt;/p&gt;

&lt;p&gt;Vivek: No Tara. Let me share my screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxnf2eefpuw1k8zjx1ewp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxnf2eefpuw1k8zjx1ewp.gif" alt="Image description" width="600" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tara: Wow.. that’s great! I just wanted to see if we could open this BottomSheet as a full screen. Just a thought. Can we do that now??&lt;/p&gt;

&lt;p&gt;Vivek: Yes Sure! let me change it to a Full Screen. Please reopen/refresh your app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3sky2n781vlvfael383.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3sky2n781vlvfael383.gif" alt="Image description" width="600" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tara: Wow, we are shuffling news also, that is great! but Vivek I feel this BottomSheet to be opened into a full screen, could be better. Is it? What if we could open up 80% of the full-screen height? What say, now feels like we need to wait for it again for a day.&lt;/p&gt;

&lt;p&gt;Vivek: Na Tara, the same thing we can do again and instantly. Just we have to set a Size here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cme3x69bfhy2eanmytd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2cme3x69bfhy2eanmytd.gif" alt="Image description" width="600" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tara: Wow am I dreaming?? That's awesome Vivek. I wanted to know which tool you are using and how you developed it. Like you, can I also make these navigation changes without touching the code?&lt;/p&gt;

&lt;p&gt;Vivek: Yes Tara, Sure you can make these changes. Here we have used a production-grade and CMS driven framework, that is Vyuh Framework.&lt;/p&gt;

&lt;p&gt;Tara: Oh I see!! Vivek, can you give me a brief introduction?&lt;/p&gt;

&lt;p&gt;Vivek: Yes Sure Tara! Vyuh is a tool that helps you build apps quickly and easily using Flutter. It uses a content management system (CMS — Sanity) to control the app, so you can make changes and add new features without needing a big team or a lot of time. This makes it super flexible and fun to work with.&lt;/p&gt;

&lt;p&gt;Key features include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Easy Updates:&lt;/strong&gt; Change your app’s look and feel without going through the app store.&lt;br&gt;
&lt;strong&gt;2. Custom Content:&lt;/strong&gt; Create and manage different types of content easily.&lt;br&gt;
&lt;strong&gt;3. Team-Friendly:&lt;/strong&gt; Smaller teams can achieve big things with Vyuh.&lt;br&gt;
&lt;strong&gt;4. Integrations:&lt;/strong&gt; Easily connect with other services and tools.&lt;br&gt;
&lt;strong&gt;5. Design Consistency:&lt;/strong&gt; Maintain a consistent look across your app using a design system.&lt;br&gt;
&lt;strong&gt;6. Powerful Tools:&lt;/strong&gt; Manage app state, navigation, and more with ease.&lt;br&gt;
&lt;strong&gt;7. Secure Storage:&lt;/strong&gt; Keep your data safe.&lt;br&gt;
Vyuh is perfect for companies wanting to build impressive apps quickly, experiment with different designs, and ensure a smooth and efficient development process.&lt;/p&gt;

&lt;p&gt;Tara: Wait, Vivek! Sorry for interrupting you, can you please tell me “Create and manage different types of content easily.” What does that mean?&lt;/p&gt;

&lt;p&gt;Vivek: Sure! For example Tara, here you can see my shared screen, right? If you want the sequence of this news home screen to change, say if you want News Group to be on the top then News List, and then News Carousel then you can make those changes from here quickly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6vgud8c5l76eev5fd1p.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6vgud8c5l76eev5fd1p.gif" alt="Image description" width="600" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tara: Ohhh I see… that’s very cool..&lt;/p&gt;

&lt;p&gt;Vivek: Yes, Vyuh is a framework designed for building production-grade Flutter apps with a CMS-driven approach. This means it uses a Content Management System to manage and drive the app’s experience, significantly reducing the time needed to add new features with a smaller team. Vyuh offers incredible flexibility and control over your app’s journey and content, making UI development fun and dynamic.&lt;/p&gt;

&lt;p&gt;The framework covers all the essentials for building large-scale apps, such as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CMS-driven (aka Server-driven) UI&lt;/li&gt;
&lt;li&gt;Custom Content types&lt;/li&gt;
&lt;li&gt;Actions, Layouts, Conditions, Routes&lt;/li&gt;
&lt;li&gt;Custom journeys &amp;amp; Conditional flows&lt;/li&gt;
&lt;li&gt;Modular development of Features with independent teams&lt;/li&gt;
&lt;li&gt;Third-party integrations via Plugins&lt;/li&gt;
&lt;li&gt;Remote configuration with Zero App Store releases&lt;/li&gt;
&lt;li&gt;Design System-based UX&lt;/li&gt;
&lt;li&gt;Analytics&lt;/li&gt;
&lt;li&gt;Feature Flags and A/B/N testing&lt;/li&gt;
&lt;li&gt;Networking&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Navigation and Routing&lt;/li&gt;
&lt;li&gt;State Management with the sophistication you desire&lt;/li&gt;
&lt;li&gt;Error Handling&lt;/li&gt;
&lt;li&gt;Theming&lt;/li&gt;
&lt;li&gt;Storage and Secure Storage
and much, much more…&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let me tell you the immediate benefits of Vyuh:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Faster App Deployments:&lt;/strong&gt; Update your app experience without needing app store releases or deployments&lt;br&gt;
&lt;strong&gt;2. Explorative Power:&lt;/strong&gt; Try different designs and user experiences without changing any code&lt;br&gt;
&lt;strong&gt;3. Small Teams, Big Outcomes:&lt;/strong&gt; Build advanced apps quickly with smaller teams&lt;br&gt;
&lt;strong&gt;4. Extensibility Built-In:&lt;/strong&gt; Customize every part of your app, from content blocks to layouts and routes.&lt;br&gt;
&lt;strong&gt;5. Design System First:&lt;/strong&gt; Ensure a consistent look across your app using a design system&lt;br&gt;
&lt;strong&gt;6. Easy Third-Party Integrations:&lt;/strong&gt; Easily connect with various APIs (like ReST, GraphQL, WebSockets) for more features&lt;br&gt;
&lt;strong&gt;7. Powerful State Management:&lt;/strong&gt; Use MobX for flexible and sophisticated app experiences&lt;br&gt;
&lt;strong&gt;8. Developer Productivity:&lt;/strong&gt; Speed up development with dynamic updates through the CMS and Flutter’s Hot Reload&lt;br&gt;
&lt;strong&gt;9. Growing Integrations:&lt;/strong&gt; Access a growing set of plugins for everything from networking to payments&lt;br&gt;
&lt;strong&gt;10. Fundamentals Ready:&lt;/strong&gt; Start your app development with built-in basic features.&lt;br&gt;
These benefits help enterprises build and manage their apps more efficiently, from flagship applications to platforms for white-labeled apps.&lt;/p&gt;

&lt;p&gt;Tara: Wow Vivek, that’s awesome!! I wanted to know more about it.&lt;/p&gt;

&lt;p&gt;Vivek: Sure, Tara you can visit this Vyuh website and as you can see in this live demo, here on this site you will get all about its features, integrations, and pricing which is very worth paying. Is it?&lt;/p&gt;

&lt;p&gt;Tara: Yeah! So grateful to be part of Vyuh and NonStop IO Technologies.&lt;/p&gt;

&lt;p&gt;Vivek: So happy to work with you. Thank you!&lt;/p&gt;

&lt;p&gt;Tara: Bye Vivek. Thank you!&lt;/p&gt;

&lt;p&gt;So after seeing this live demo given by Vivek, you can imagine how customizable, comprehensive, and extensible this Vyuh framework is! It provides us with the thought that rather than thinking of your App in terms of screens of content, you make an important mind-shift: “Think of your app as a collection of features where each feature contributes a set of components”. So let’s be ready for the surprises that are coming from Vyuh Framework. Stay tuned!&lt;/p&gt;

&lt;p&gt;Hope you enjoyed this article!&lt;/p&gt;

&lt;p&gt;Ref: &lt;a href="https://vyuh.nonstopio.com/" rel="noopener noreferrer"&gt;Vyuh Framework&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>sanity</category>
      <category>appdevelopement</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
