<?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 Anik Adhikary on Medium]]></title>
        <description><![CDATA[Stories by Anik Adhikary on Medium]]></description>
        <link>https://medium.com/@anikadhikary?source=rss-851e910c8d32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*x5tVoxm897zYz6Ye.</url>
            <title>Stories by Anik Adhikary on Medium</title>
            <link>https://medium.com/@anikadhikary?source=rss-851e910c8d32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:58:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anikadhikary/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[Vue 3 Part 3: Mastering Directives with Practical Examples]]></title>
            <link>https://medium.com/@anikadhikary/vue-3-part-3-mastering-directives-with-practical-examples-30dde27551fc?source=rss-851e910c8d32------2</link>
            <guid isPermaLink="false">https://medium.com/p/30dde27551fc</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Anik Adhikary]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 07:44:55 GMT</pubDate>
            <atom:updated>2024-11-15T07:44:55.079Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Directives in Vue 3 provide powerful tools to manipulate the DOM dynamically. Built-in directives like v-bind, v-model, v-if, v-for, and v-on enable developers to create interactive and reactive applications effortlessly. This article dives straight into these directives with detailed real-world examples, including how to create custom directives for advanced use cases.</p><h3>Built-In Directives</h3><h3>v-bind: Dynamic Attribute Binding</h3><p>v-bind is used to dynamically bind attributes such as src, alt, class, or style to reactive properties.</p><p><strong>Example: Binding Image Attributes Dynamically</strong></p><pre>&lt;template&gt;<br>  &lt;img :src=&quot;imageSrc&quot; :alt=&quot;imageAlt&quot; /&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { ref } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const imageSrc = ref(&#39;/images/vue-logo.png&#39;);<br>    const imageAlt = ref(&#39;Vue Logo&#39;);<br>    return { imageSrc, imageAlt };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The src and alt attributes dynamically update based on the reactive imageSrc and imageAlt properties.</li></ul><h3>v-model: Two-Way Data Binding</h3><p>v-model enables two-way binding between form inputs and reactive properties, making it ideal for forms and user input.</p><p><strong>Example: Live Preview for User Input</strong></p><pre>&lt;template&gt;<br>  &lt;form @submit.prevent=&quot;handleSubmit&quot;&gt;<br>    &lt;label&gt;<br>      Name:<br>      &lt;input v-model=&quot;name&quot; /&gt;<br>    &lt;/label&gt;<br>    &lt;p&gt;Hello, {{ name }}!&lt;/p&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>  &lt;/form&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { ref } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const name = ref(&#39;&#39;);</pre><pre>    const handleSubmit = () =&gt; {<br>      alert(`Submitted: ${name.value}`);<br>    };</pre><pre>    return { name, handleSubmit };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The v-model directive binds the input’s value to the name property, ensuring changes to the input are reflected in real-time.</li></ul><h3>v-if, v-else-if, and v-else: Conditional Rendering</h3><p>These directives allow you to conditionally render elements based on reactive expressions.</p><p><strong>Example: Displaying Login or Logout Buttons</strong></p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;button v-if=&quot;!isLoggedIn&quot; @click=&quot;login&quot;&gt;Log In&lt;/button&gt;<br>    &lt;button v-else @click=&quot;logout&quot;&gt;Log Out&lt;/button&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { ref } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const isLoggedIn = ref(false);</pre><pre>    const login = () =&gt; {<br>      isLoggedIn.value = true;<br>    };</pre><pre>    const logout = () =&gt; {<br>      isLoggedIn.value = false;<br>    };</pre><pre>    return { isLoggedIn, login, logout };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The v-if directive displays the &quot;Log In&quot; button if the user is not logged in, while the &quot;Log Out&quot; button appears when the user is logged in.</li></ul><h3>v-for: Looping Through Arrays</h3><p>v-for renders lists by looping through arrays or objects.</p><p><strong>Example: Rendering a Dynamic Task List</strong></p><pre>&lt;template&gt;<br>  &lt;ul&gt;<br>    &lt;li v-for=&quot;task in tasks&quot; :key=&quot;task.id&quot;&gt;<br>      {{ task.name }}<br>    &lt;/li&gt;<br>  &lt;/ul&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { ref } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const tasks = ref([<br>      { id: 1, name: &#39;Learn Vue 3&#39; },<br>      { id: 2, name: &#39;Build a project&#39; }<br>    ]);</pre><pre>    return { tasks };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The v-for directive iterates over the tasks array, dynamically rendering each task in the list.</li></ul><h3>v-on: Event Handling</h3><p>v-on binds event listeners to DOM elements. The shorthand @ simplifies the syntax for cleaner templates.</p><p><strong>Example: Adding an Item to Favorites</strong></p><pre>&lt;template&gt;<br>  &lt;button @click=&quot;addToFavorites&quot;&gt;Add to Favorites&lt;/button&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>export default {<br>  setup() {<br>    const addToFavorites = () =&gt; {<br>      alert(&#39;Added to favorites!&#39;);<br>    };</pre><pre>    return { addToFavorites };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The button click triggers the addToFavorites method, which performs the desired action.</li></ul><h3>Custom Directives</h3><p>Custom directives allow you to extend Vue’s functionality for DOM manipulation that isn’t covered by built-in directives.</p><h3>Example: Auto-Focus with a Custom Directive</h3><p><strong>Step 1: Define the Custom Directive</strong></p><pre>const vFocus = {<br>  mounted(el) {<br>    el.focus();<br>  }<br>};</pre><p><strong>Step 2: Use the Directive in a Component</strong></p><pre>&lt;template&gt;<br>  &lt;input v-focus placeholder=&quot;Focus on me!&quot; /&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { vFocus } from &#39;./directives/focus&#39;;</pre><pre>export default {<br>  directives: {<br>    focus: vFocus<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>: The vFocus directive automatically focuses the input element when the component mounts.</li></ul><h3>Combining Directives for Advanced Use Cases</h3><p>Directives can be combined for more complex behaviors. For example, a login form can use v-model, v-if, and v-on together to handle user input and validation.</p><h3>Example: Login Form with Validation</h3><pre>&lt;template&gt;<br>  &lt;form @submit.prevent=&quot;login&quot;&gt;<br>    &lt;div&gt;<br>      &lt;label&gt;Email:&lt;/label&gt;<br>      &lt;input v-model=&quot;email&quot; /&gt;<br>    &lt;/div&gt;<br>    &lt;div&gt;<br>      &lt;label&gt;Password:&lt;/label&gt;<br>      &lt;input type=&quot;password&quot; v-model=&quot;password&quot; /&gt;<br>    &lt;/div&gt;<br>    &lt;button :disabled=&quot;!isFormValid&quot;&gt;Log In&lt;/button&gt;<br>  &lt;/form&gt;<br>  &lt;p v-if=&quot;errorMessage&quot; class=&quot;error&quot;&gt;{{ errorMessage }}&lt;/p&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import { ref, computed } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const email = ref(&#39;&#39;);<br>    const password = ref(&#39;&#39;);<br>    const errorMessage = ref(&#39;&#39;);</pre><pre>    const isFormValid = computed(() =&gt; email.value &amp;&amp; password.value);</pre><pre>    const login = () =&gt; {<br>      if (!isFormValid.value) {<br>        errorMessage.value = &#39;All fields are required!&#39;;<br>        return;<br>      }<br>      alert(`Logged in with: ${email.value}`);<br>      errorMessage.value = &#39;&#39;;<br>    };</pre><pre>    return { email, password, errorMessage, isFormValid, login };<br>  }<br>};<br>&lt;/script&gt;</pre><ul><li><strong>Explanation</strong>:</li><li>v-model binds the input fields to reactive properties.</li><li>v-if displays an error message conditionally.</li><li>v-on listens for the form submit event and executes the login method.</li></ul><h3>Conclusion</h3><p>In this article, we explored Vue 3’s built-in directives (v-bind, v-model, v-if, v-for, and v-on) with practical examples and introduced custom directives to handle advanced use cases.</p><p>Mastering directives allows you to create dynamic, user-friendly applications efficiently. By combining and customizing directives, you can create powerful and highly interactive applications with Vue 3. Stay tuned for the next article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30dde27551fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue 3 Part 2: Lifecycle Hooks, Watchers, Props and Emits]]></title>
            <link>https://medium.com/@anikadhikary/vue-3-part-2-lifecycle-hooks-watchers-and-props-40e2242d442e?source=rss-851e910c8d32------2</link>
            <guid isPermaLink="false">https://medium.com/p/40e2242d442e</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue-3]]></category>
            <dc:creator><![CDATA[Anik Adhikary]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 07:31:52 GMT</pubDate>
            <atom:updated>2024-11-15T14:13:04.208Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Vue 3 provides a structured way to manage component behaviour with <strong>lifecycle hooks</strong>, <strong>watchers</strong>, <strong>props </strong>and<strong> emits</strong>. These features allow developers to control component life stages, respond to reactive data changes, and share data between components seamlessly. In this article, we’ll explore these core concepts in detail, backed by real-world examples.</p><h3>1. Lifecycle Hooks</h3><p>Lifecycle hooks let you control a component’s behavior during its life stages, such as initialization, updates, and cleanup. They’re essential for managing asynchronous tasks, setting up resources, or cleaning up when components are destroyed.</p><h3>Key Hooks and Their Usage</h3><ol><li><strong>onMounted</strong>: Runs after the component is added to the DOM. Ideal for tasks like fetching data or initializing third-party libraries.</li><li><strong>onUpdated</strong>: Runs after reactive data changes and the DOM updates. Useful for syncing DOM elements or side effects.</li><li><strong>onUnmounted</strong>: Runs before the component is removed from the DOM. Perfect for cleaning up resources like timers or event listeners.</li></ol><h3>Examples</h3><h4>onMounted Example: Fetching Data on Component Mount</h4><p>Let’s build a component that fetches the latest news articles when it mounts.</p><pre>import { ref, onMounted } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const articles = ref([]);<br>    const isLoading = ref(true);</pre><pre>    onMounted(async () =&gt; {<br>      try {<br>        const response = await fetch(&#39;https://api.example.com/articles&#39;);<br>        articles.value = await response.json();<br>      } finally {<br>        isLoading.value = false;<br>      }<br>    });</pre><pre>    return { articles, isLoading };<br>  }<br>};</pre><p><strong>Explanation</strong>:</p><ul><li>onMounted fetches articles from an API once the component is mounted.</li><li>isLoading manages the loading state and can be used in the template to show a spinner while the data is being fetched.</li></ul><h4>onUpdated Example: Updating the Page Title on Reactive Changes</h4><p>You can use onUpdated to synchronize the document title with a reactive property like the current page’s title.</p><pre>import { ref, onUpdated } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const pageTitle = ref(&quot;Home&quot;);</pre><pre>    onUpdated(() =&gt; {<br>      document.title = pageTitle.value;<br>    });</pre><pre>    return { pageTitle };<br>  }<br>};</pre><p><strong>Explanation</strong>:</p><ul><li>Whenever pageTitle changes and the DOM updates, onUpdated updates the browser’s title bar.</li></ul><h4>onUnmounted Example: Clearing an Interval on Component Unmount</h4><p>When using timers, it’s crucial to clear them when the component is destroyed. onUnmounted ensures cleanup.</p><pre>import { ref, onMounted, onUnmounted } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const count = ref(0);<br>    let interval;</pre><pre>    onMounted(() =&gt; {<br>      interval = setInterval(() =&gt; {<br>        count.value++;<br>      }, 1000);<br>    });</pre><pre>    onUnmounted(() =&gt; {<br>      clearInterval(interval);<br>    });</pre><pre>    return { count };<br>  }<br>};</pre><p><strong>Explanation</strong>:</p><ul><li>onMounted starts a timer to increment count every second.</li><li>onUnmounted clears the interval to prevent memory leaks when the component is destroyed.</li></ul><h3>2. Watchers: watch and watchEffect</h3><p>Watchers let you track changes to reactive properties and execute logic in response. Vue 3 offers two types:</p><ul><li><strong>watch</strong>: Monitors specific variables or computed properties and triggers a function when they change.</li><li><strong>watchEffect</strong>: Automatically tracks all reactive properties used within its scope and reruns whenever any of them change.</li></ul><h3>Examples</h3><h4>watch Example: Implementing a Live Search Feature</h4><p>In a search component, you can use watch to fetch results every time the search query changes.</p><pre>import { ref, watch } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const searchQuery = ref(&#39;&#39;);<br>    const results = ref([]);<br>    const isSearching = ref(false);</pre><pre>    watch(searchQuery, async (newQuery) =&gt; {<br>      if (!newQuery) {<br>        results.value = [];<br>        return;<br>      }</pre><pre>      isSearching.value = true;<br>      const response = await fetch(`https://api.example.com/search?q=${newQuery}`);<br>      results.value = await response.json();<br>      isSearching.value = false;<br>    });</pre><pre>    return { searchQuery, results, isSearching };<br>  }<br>};</pre><p><strong>Explanation</strong>:</p><ul><li>watch observes searchQuery. When it changes, it triggers an API call to fetch results.</li><li>isSearching is updated to indicate whether a search is in progress.</li></ul><h4>watchEffect Example: Saving Form Data to Local Storage</h4><p>Use watchEffect to automatically track dependencies and save form data to local storage whenever it updates.</p><pre>import { reactive, watchEffect } from &#39;vue&#39;;</pre><pre>export default {<br>  setup() {<br>    const formData = reactive({<br>      name: &#39;&#39;,<br>      email: &#39;&#39;<br>    });</pre><pre>    watchEffect(() =&gt; {<br>      localStorage.setItem(&#39;formData&#39;, JSON.stringify(formData));<br>    });</pre><pre>    return { formData };<br>  }<br>};</pre><p><strong>Explanation</strong>:</p><ul><li>watchEffect tracks formData. Whenever any property (name or email) changes, the effect runs and updates local storage.</li></ul><h3>3. Props and Emits: Sharing Data and Communicating Between Components</h3><p><strong>Props</strong> enable data sharing between parent and child components, making them reusable and modular. <strong>Emits</strong> allow child components to communicate back to their parents by triggering events.</p><h4>Example: Building a Reusable Product Card Component</h4><p>In an e-commerce app, you might use a ProductCard component to display individual product details.</p><p>Step 1: Define ProductCard.vue</p><pre>&lt;template&gt;<br>  &lt;div class=&quot;product-card&quot;&gt;<br>    &lt;img :src=&quot;product.image&quot; :alt=&quot;product.name&quot; /&gt;<br>    &lt;h3&gt;{{ product.name }}&lt;/h3&gt;<br>    &lt;p&gt;{{ product.description }}&lt;/p&gt;<br>    &lt;span&gt;\${{ product.price }}&lt;/span&gt;<br>    &lt;button @click=&quot;addToCart&quot;&gt;Add to Cart&lt;/button&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>  props: {<br>    product: {<br>      type: Object,<br>      required: true<br>    }<br>  },<br>  methods: {<br>    addToCart() {<br>      this.$emit(&#39;add-to-cart&#39;, this.product);<br>    }<br>  }<br>};<br>&lt;/script&gt;</pre><p><strong>Explanation</strong>:</p><ul><li>product is passed as a prop to the ProductCard component.</li><li>addToCart emits an event with the product data when the &quot;Add to Cart&quot; button is clicked.</li></ul><p>Step 2: Use ProductCard in the Parent Component</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;ProductCard<br>      v-for=&quot;product in products&quot;<br>      :key=&quot;product.id&quot;<br>      :product=&quot;product&quot;<br>      @add-to-cart=&quot;handleAddToCart&quot;<br>    /&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import ProductCard from &#39;./ProductCard.vue&#39;;<br>export default {<br>  components: { ProductCard },<br>  setup() {<br>    const products = ref([<br>      { id: 1, name: &#39;Product A&#39;, price: 20, description: &#39;Description A&#39;, image: &#39;/img/a.jpg&#39; },<br>      { id: 2, name: &#39;Product B&#39;, price: 30, description: &#39;Description B&#39;, image: &#39;/img/b.jpg&#39; }<br>    ]);<br>    const handleAddToCart = (product) =&gt; {<br>      console.log(&#39;Added to cart:&#39;, product);<br>    };<br>    return { products, handleAddToCart };<br>  }<br>};<br>&lt;/script&gt;</pre><p><strong>Explanation</strong>:</p><ul><li>The parent component passes product data to ProductCard via the product prop.</li><li>handleAddToCart listens for the add-to-cart event emitted by the child component.</li></ul><h3>Conclusion</h3><p>In this article, we covered the core features of Vue 3:</p><ul><li><strong>Lifecycle Hooks</strong>: Managing component behavior during different life stages.</li><li><strong>Watchers</strong>: Tracking and responding to reactive data changes.</li><li><strong>Props and Emits</strong>: Sharing data between parent and child components and enabling communication.</li></ul><p>These tools allow developers to create modular, reactive, and efficient applications.</p><p>In <strong>Part 3</strong>, we’ll explore Vue 3 <strong>directives</strong> in detail, including their real-world applications and custom implementations.</p><p><strong>[Part 3: Mastering Vue 3 Directives]</strong> (Coming Soon)</p><p>By mastering lifecycle hooks, watchers, and props, you can build highly reactive and interactive Vue applications. Stay tuned for the next part, where we’ll dive deep into directives!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40e2242d442e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue 3 Part 1: How Vue 3 Brings Reactivity to JavaScript Objects]]></title>
            <link>https://medium.com/@anikadhikary/vue-3-part-1-how-vue-3-brings-reactivity-to-javascript-objects-bc7db341d8e3?source=rss-851e910c8d32------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc7db341d8e3</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue-3]]></category>
            <dc:creator><![CDATA[Anik Adhikary]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 07:20:45 GMT</pubDate>
            <atom:updated>2024-11-15T07:20:45.475Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Vue 3 introduced a powerful new reactivity system that makes developing responsive applications easier and more intuitive. This system is close to native JavaScript, allowing developers to use familiar data types while benefiting from Vue’s built-in reactivity. In this article, we’ll dive into how Vue 3’s reactivity compares to standard JavaScript objects and data types, making it easier for JavaScript developers to adopt and work with Vue.</p><h3>Understanding Reactivity in Vue 3 vs. JavaScript</h3><p>Vue 3’s reactivity system is largely built around reactive and ref. These two tools enable data to be tracked and updated within Vue components, instantly reflecting changes in the UI. This comparison helps illustrate how Vue 3’s reactivity system handles different data types.</p><h3>1. Objects and Nested Objects</h3><p>In JavaScript, objects are used to store multiple values in a single variable, but they lack automatic reactivity.</p><ul><li><strong>JavaScript Example</strong>:</li><li>const state = { count: 0, name: &#39;Vue User&#39; }; state.count++; // No automatic UI update</li><li><strong>Vue 3 Example</strong>:</li><li>import { reactive } from &#39;vue&#39;; const state = reactive({ count: 0, name: &#39;Vue User&#39; }); state.count++; // UI updates automatically if used in a template</li></ul><p>In Vue 3, using reactive turns state into a reactive object. Updates to state.count will automatically trigger UI re-renders, making data handling in Vue much simpler and more declarative.</p><h3>2. Arrays</h3><p>Vue 3’s reactivity also works seamlessly with arrays, making it easy to track additions, deletions, and changes.</p><ul><li><strong>JavaScript Example</strong>:</li><li>const items = [1, 2, 3]; items.push(4); // Update, but no reactivity for UI updates</li><li><strong>Vue 3 Example</strong>:</li><li>const items = reactive([1, 2, 3]); items.push(4); // Automatically triggers UI update</li></ul><p>Arrays in Vue 3 become reactive with reactive, updating the UI whenever there are changes, such as pushing or removing items.</p><h3>3. Primitive Data Types with ref</h3><p>In Vue 3, single primitive values like strings, numbers, and booleans are made reactive using ref.</p><ul><li><strong>JavaScript Example</strong>:</li><li>let count = 0; count++; // No reactivity</li><li><strong>Vue 3 Example</strong>:</li><li>import { ref } from &#39;vue&#39;; const count = ref(0); count.value++; // UI updates reactively</li></ul><p>Here, ref creates a reactive variable, making it possible to use primitives reactively in Vue, which wouldn’t normally work in standard JavaScript.</p><h3>4. Functions and Computed Properties</h3><p>In JavaScript, functions are used for calculations and data transformations but don’t automatically update when dependencies change. Vue 3’s computed property makes functions reactive.</p><ul><li><strong>JavaScript Example</strong>:</li><li>const getUserName = (user) =&gt; `User: ${user.name}`;</li><li><strong>Vue 3 Example</strong>:</li><li>import { reactive, computed } from &#39;vue&#39;; const user = reactive({ name: &#39;Vue User&#39; }); const userName = computed(() =&gt; `User: ${user.name}`);</li></ul><p>With computed, Vue 3 allows functions to become reactive, automatically updating their result when any dependencies change, making data flow simpler and more declarative.</p><h3>5. Maps and Sets</h3><p>Vue 3 can make Map and Set collections reactive, although deep reactivity isn’t fully supported in some cases.</p><ul><li><strong>JavaScript Example</strong>:</li><li>const map = new Map(); map.set(&#39;key&#39;, &#39;value&#39;); // Standard JS map, no reactivity</li><li><strong>Vue 3 Example</strong>:</li><li>const map = reactive(new Map()); map.set(&#39;key&#39;, &#39;value&#39;); // Map with reactivity</li></ul><p>With Vue’s reactive, you can track updates on collections like Map and Set that aren’t natively reactive in JavaScript.</p><h3>Comparison Table</h3><p>For a quick reference, here’s how Vue 3’s reactivity differs from standard JavaScript objects:</p><ul><li><strong>Object</strong>: { count: 0 } → reactive({ count: 0 })</li><li><strong>Nested Object</strong>: { profile: { age: 25 } } → reactive({ profile: { age: 25 } })</li><li><strong>Array</strong>: [1, 2, 3] → reactive([1, 2, 3])</li><li><strong>Primitive (number)</strong>: let count = 0 → const count = ref(0)</li><li><strong>Function</strong>: const func = () =&gt; {} → const func = computed(() =&gt; {})</li><li><strong>Map</strong>: const map = new Map() → const map = reactive(new Map())</li></ul><h3>Conclusion</h3><p>Vue 3’s reactivity system provides the power of reactive data with the familiarity of JavaScript objects, arrays, maps, and other data structures. This makes it easier to adopt and implement reactivity in applications while keeping your code clean and concise.</p><p>Developers get the best of both worlds: familiar JavaScript syntax combined with the reactivity needed to build dynamic and modern web applications. Whether you’re new to Vue or an experienced developer, understanding the underlying reactivity model can make a huge difference in how you structure and maintain your Vue projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc7db341d8e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>