<?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 Dimeji Ogunleye on Medium]]></title>
        <description><![CDATA[Stories by Dimeji Ogunleye on Medium]]></description>
        <link>https://medium.com/@dimeji.ogunleye20?source=rss-8ef00c0ad30d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kf-XB71dSZW94TSj</url>
            <title>Stories by Dimeji Ogunleye on Medium</title>
            <link>https://medium.com/@dimeji.ogunleye20?source=rss-8ef00c0ad30d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:06:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dimeji.ogunleye20/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[Creating a modal using Vue refs and HTML Dialogue element]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@dimeji.ogunleye20/creating-a-modal-using-vue-refs-and-html-dialogue-element-342b3f25832e?source=rss-8ef00c0ad30d------2"><img src="https://cdn-images-1.medium.com/max/1022/1*y0tXoQ3wWk_fLZWisTXJpA@2x.jpeg" width="1022"></a></p><p class="medium-feed-snippet">Over the years developers have had to ship in component libraries as a quick way to bootstrap modals for their projects because HTML&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@dimeji.ogunleye20/creating-a-modal-using-vue-refs-and-html-dialogue-element-342b3f25832e?source=rss-8ef00c0ad30d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@dimeji.ogunleye20/creating-a-modal-using-vue-refs-and-html-dialogue-element-342b3f25832e?source=rss-8ef00c0ad30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/342b3f25832e</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Dimeji Ogunleye]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 09:52:49 GMT</pubDate>
            <atom:updated>2024-10-30T07:52:47.878Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[3 Patterns for better Vue components.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@dimeji.ogunleye20/3-patterns-for-better-vue-components-a6fe431c6264?source=rss-8ef00c0ad30d------2"><img src="https://cdn-images-1.medium.com/max/600/1*Jmxyl0daHrUxhVWxdseNcQ.jpeg" width="600"></a></p><p class="medium-feed-snippet">Vue.js has rapidly become a go to solution among developers for building robust and reactive web applications. Its component-based&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@dimeji.ogunleye20/3-patterns-for-better-vue-components-a6fe431c6264?source=rss-8ef00c0ad30d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@dimeji.ogunleye20/3-patterns-for-better-vue-components-a6fe431c6264?source=rss-8ef00c0ad30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6fe431c6264</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Dimeji Ogunleye]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 14:17:19 GMT</pubDate>
            <atom:updated>2024-08-02T14:17:19.495Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Nuxt 3 useFetch — Are you using it correctly?]]></title>
            <link>https://medium.com/@dimeji.ogunleye20/nuxt-3-usefetch-are-you-using-it-correctly-baf193dcf40b?source=rss-8ef00c0ad30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/baf193dcf40b</guid>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[technews]]></category>
            <dc:creator><![CDATA[Dimeji Ogunleye]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 12:11:04 GMT</pubDate>
            <atom:updated>2024-08-13T12:32:33.462Z</atom:updated>
            <content:encoded><![CDATA[<h3>Nuxt 3 useFetch — Are you using it correctly?</h3><figure><img alt="Debugging due to unexpected behaviours." src="https://cdn-images-1.medium.com/max/1024/1*o9aLpyHB7BBou8ekhmKfrA.png" /><figcaption>Debugging due to unexpected behaviours.</figcaption></figure><h3>Introduction</h3><p>Usefetch is a composable that comes readily with Nuxt 3, it’s a convenient wrapper around <strong>useAsyncData</strong> and <strong>$fetch </strong>that simplifies the process of data fetching by handling most of the logic while exposing<strong> </strong>useful <strong>reactive</strong> <strong>refs</strong> and <strong>functions</strong>.</p><p>While useFetch composable provides an easy way of fetching data, when not properly used it can result into unexpected behaviours.</p><p>Generally as a rule guiding composables, they must be called only in;</p><ol><li>A setup function.</li><li>Plugins.</li><li>Route Middleware.</li></ol><p>Trying to use this composable outside this scope will lead to bugs that affects performance of the app.</p><p>In this article, I’ll explore two effective approaches to utilizing composables in Nuxt. To illustrate these methods, I’ve set up a demo Nuxt application that you can clone from this <a href="https://github.com/Kinglemar/using_useFetch_correctly"><strong>repository</strong></a><strong> </strong>then run<strong> </strong><strong>pnpm i to </strong>install dependencies.</p><h3>Calling useFetch in a function or an event handler.</h3><p>In this demo I made an Api call to get user credential from an external source. To get started, let’s look at an example of the script setup:</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>const data = ref();<br>const loading = ref(false);<br>const errorOccured = ref(false);<br><br>async function sendData() {<br>  loading.value = true;<br>  const {<br>    data: apiData,<br>    error,<br>    pending,<br>  } = await useFetch(&quot;https://dummyjson.com/user/login&quot;, {<br>    method: &quot;POST&quot;,<br>    body: user.value,<br>  });<br><br>  if (apiData.value) {<br>    data.value = apiData.value;<br>  }<br>  if (error.value) {<br>    errorOccured.value = true;<br>  }<br>  loading.value = false;<br>}<br><br>const user = ref({<br>  username: &quot;&quot;,<br>  password: &quot;&quot;,<br>});<br>&lt;/script&gt;</pre><p>Here’s the resultant UI (User interface).</p><figure><img alt="Snapshot of login form." src="https://cdn-images-1.medium.com/max/1024/1*Z7oOWmJAKX-YzUJyXO8rBg.png" /><figcaption>Snapshot of login form.</figcaption></figure><p>Everything looks normal so far, our form is ready for user interactivity. When the form is being populated and the button is being pushed, the call to the external Api works as expected, but there’s a friendly error in our console.</p><figure><img alt="Console informations." src="https://cdn-images-1.medium.com/max/1024/1*qvZD_jFonoWmSb73ZjChtQ.png" /><figcaption>Console informations.</figcaption></figure><p>This issue often arises from incorrect usage of <strong>useFetch</strong>. This error get’s messier when the initial call fails and the user tries to edit the form field, multiple calls are initiated with each stroke of the keyboard by the user. This is happening because <strong>useFetch</strong> <strong>watches</strong> the <strong>body value</strong> by default and will make new calls since there’s a change in the body value.</p><p>This will result to performance issues over time. Below is an image to show the network’s tab on chrome dev tools.</p><figure><img alt="Screenshot of network’s tab." src="https://cdn-images-1.medium.com/max/600/1*cq6yzUoFUYVKA0YCP-4Mng.gif" /><figcaption>Screenshot of the network’s tab.</figcaption></figure><p>We can address this issue with two approaches, which I will share shortly.</p><h4><strong>First Approach</strong></h4><p>The first approach involves us using the <strong>useFetch</strong> composable in the script setup but not in the event handler, but we pass along more argument to tell <strong>Nuxt</strong> not to fire the request immediately, then we call <strong>execute</strong> callback function when we want to.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>type User = {<br>  id: number;<br>  email: string;<br>  username: string;<br>  firstName: string;<br>  gender: string;<br>  image: string;<br>  lastName: string;<br>  refreshToken: string;<br>  token: string;<br>};<br><br>const userCredentials = ref({<br>  username: &quot;emilys&quot;,<br>  password: &quot;emilyspass&quot;,<br>});<br><br>const {<br>  data,<br>  execute,<br>  pending,<br>  error,<br>  status,<br>} = useFetch&lt;User&gt;(&quot;https://dummyjson.com/user/login&quot;, {<br>  method: &quot;POST&quot;,<br>  body: userCredentials.value,<br>  immediate: false,<br>  lazy: true,<br>});<br>&lt;/script&gt;</pre><p>The <strong>execute</strong> function is then hooked to the button event. With this we make the request and everything works fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*EH6MRxJ3mf4hH4wVyrOWhA.gif" /><figcaption>No friendly error in the console.</figcaption></figure><h4><strong>Second Approach</strong></h4><p>We replace <strong>useFetch</strong> composable with <strong>$fetch </strong>and wrap in try catch block. Using $fetch within event handlers is the recommended approach, as it is a utility function provided by Nuxt that functions well when called in such contexts. Additionally, <strong>$fetch</strong> can be called within our Nuxt app or API routes.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>const data = ref();<br>const loading = ref(false);<br>const errorOccured = ref(false);<br><br>async function sendDataUsing$Fetch() {<br>  try {<br>    loading.value = true;<br>    const apiData = await $fetch(&quot;https://dummyjson.com/user/login&quot;, {<br>      method: &quot;POST&quot;,<br>      body: user.value,<br>    });<br><br>    if (apiData) {<br>      data.value = apiData;<br>    }<br>    loading.value = false;<br>  } catch {<br>    loading.value = false;<br>    errorOccured.value = true;<br>  }<br>}<br><br>const user = ref({<br>  username: &quot;&quot;,<br>  password: &quot;&quot;,<br>});<br>&lt;/script&gt;</pre><p>When we call the <strong>sendDataUsing$Fetch </strong>function<strong> </strong>by clicking the button, everything works as expected.</p><figure><img alt="Demo of the result." src="https://cdn-images-1.medium.com/max/600/1*4Kju4bpXzLGfTZemLpzs3g.gif" /><figcaption>Demo of the result.</figcaption></figure><h3><strong>In conclusion</strong></h3><p>Nuxt provides us with great composables and utils functions that we can readily opt into for better developer experience and faster development cycle. Using these features correctly greatly impacts the performance of our app.</p><p>It is recommended to <strong>$fetch</strong> with <strong>useAsyncData </strong>in script setup tag which serves as convenient wrapper for <strong>$fetch</strong> to avoid data being fetched twice, once on the server and also on the client side. You can read more about it on this <a href="https://nuxt.com/docs/api/utils/dollarfetch"><strong>page</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baf193dcf40b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common Vuejs Development Mistakes]]></title>
            <link>https://medium.com/@dimeji.ogunleye20/common-vuejs-development-mistakes-10877bdc591d?source=rss-8ef00c0ad30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/10877bdc591d</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[technology-news]]></category>
            <dc:creator><![CDATA[Dimeji Ogunleye]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 12:10:14 GMT</pubDate>
            <atom:updated>2024-08-13T12:35:10.749Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Stressed after debugging." src="https://cdn-images-1.medium.com/max/1024/1*MdEXpNwOxT9gv4eRW9ke-w.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>Vuejs offers developers a rich set of features to speed up development while delivering a robust and performance critical application.</p><p>Even with their benefits, these features can turn into sources of bugs if not used correctly, leading to prolonged debugging sessions for developers. Bugs are not application friendly and eventually will affect overall performance of the Vue app.</p><p>We will be learning from the mistakes of other so as to be able to write clean code while retaining features and performance of the app, with this let’s get started.</p><p>For this article, I set up a minimal Vue app with Vite. You can clone the project from this <a href="https://github.com/Kinglemar/common-mistakes-vuejs"><strong>repository</strong></a>. Once you have it on your local machine, run <strong>pnpm i</strong> to install the dependencies and start the development server.</p><h3>Scenario — 1 : Using non unique Id’s for V-for loops.</h3><p>This bug can be reproduced when specific conditions are met;</p><ol><li>Re-ordering elements in an array.</li><li>When a component in the loop has internal state.</li></ol><p>For demonstration purposes, consider this code snippet;</p><pre>async function fetchData() {<br>  try {<br>    const dataFromApi = await axios.get(<br>      &quot;https://dummyjson.com/recipes?page=1&amp;limit=10&amp;skip=10&amp;select=name,image&quot;<br>    );<br>    const recipes = dataFromApi.data.recipes as Recipe[];<br><br>    favoriteRecipeList.value = [...favoriteRecipeList.value, ...recipes];<br>    isLoading.value = false;<br>  } catch (e) {<br>    isLoading.value = false;<br>    console.log(e);<br>  }<br>}</pre><p>This function fetches data from a source and populates a local variable which would be looped over to render a list of recipes, bearing in mind that the <strong>SingleRecipe</strong> component has it’s own internal state;</p><pre><br>&lt;template&gt;<br>  &lt;main class=&quot;md:min-h-screen md:p-5 p-2&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl&quot;&gt;Ouch, Mistakes.&lt;/h1&gt;<br><br>    &lt;section<br>      v-if=&quot;isLoading&quot;<br>      class=&quot;w-full h-72 flex flex-col items-center justify-center&quot;<br>    &gt;<br>      &lt;p class=&quot;text-3xl&quot;&gt;Loading...&lt;/p&gt;<br>    &lt;/section&gt;<br><br>    &lt;section<br>      v-auto-animate<br>      v-else<br>      class=&quot;w-full grid md:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-3 mt-16 relative mb-14&quot;<br>    &gt;<br>      &lt;button<br>        :disabled=&quot;!haveRecipes&quot;<br>        @click=&quot;shuffleRecipe&quot;<br>        class=&quot;px-4 py-1.5 absolute -top-16 right-5 bg-green-700 text-white&quot;<br>      &gt;<br>        Shuffle<br>      &lt;/button&gt;<br>      &lt;SingleRecipe<br>        v-for=&quot;(item, index) in favoriteRecipeList&quot;<br>        :key=&quot;index&quot;<br>        :recipe=&quot;item&quot;<br>      /&gt;<br>    &lt;/section&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><p>Here’s the result of this demo;</p><figure><img alt="Image to show shuffling of recipes" src="https://cdn-images-1.medium.com/max/600/1*olKHInFxTmp3V2QVBQ8LCQ.gif" /><figcaption>Image to show shuffling of recipes</figcaption></figure><p>Everything looks normal since we provided index as the key of the loop. When we hit the shuffle button, Although the order of the recipes changes, it appears that the intended transition is not functioning.</p><p>That’s because <strong>Vue uses these keys</strong> to force a <strong>re-render</strong> whenever there’s a <strong>change</strong> in the key, since we used index that remains constant even when we shuffle, the index remains the same and the transition won’t work since there’s no re-render.</p><p>To fix this we will use a more unique key to help Vue track changes that occur in the list;</p><pre> &lt;SingleRecipe<br>   v-for=&quot;item in favoriteRecipeList&quot;<br>   :key=&quot;item.name&quot;<br>   :recipe=&quot;item&quot;<br> /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*G4ZeO7zeaaZg7cTeAbtzQQ.gif" /><figcaption>Image to show smoothly transitioning recipe cards.</figcaption></figure><p>As seen above the transition works as expected.</p><h3><strong>Scenario — 2: Non reactive value as a dependency</strong></h3><p>Often developers need some reactivity when working with browser API’s, like local storage and geolocation. Conventionally browser API’s aren’t reactive so developers get tricked into using these API as computed values.</p><p>Below is a snippet of our script tag that contains a ref that has access to properties of a video element.</p><p>As seen — a computed value is used to track the playing state of the video.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { ref, computed } from &quot;vue&quot;;<br>import PlayButton from &quot;@/components/icons/PlayButton.vue&quot;;<br>import PauseButton from &quot;@/components/icons/PauseButton.vue&quot;;<br><br>const videoPlayer = ref&lt;HTMLVideoElement&gt;();<br>const playing = computed(() =&gt; !videoPlayer.value?.paused);<br><br>&lt;/script&gt;</pre><p>The computed value is used on the template to display playing and pause state of the video.</p><pre>&lt;template&gt;<br>  &lt;main class=&quot;md:min-h-screen md:p-5 p-2&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl&quot;&gt;Ouch, Mistakes. - Non reactive dependency.&lt;/h1&gt;<br><br>    &lt;section class=&quot;mt-16 relative&quot;&gt;<br>      &lt;video src=&quot;/shrek_meets_donkey.mp4&quot; ref=&quot;videoPlayer&quot; class=&quot;mx-auto h-96&quot; /&gt;<br>      &lt;div<br>        v-auto-animate<br>        class=&quot;inline-flex gap-3 absolute top-[48%] right-[46%]&quot;<br>      &gt;<br>        &lt;button<br>          @click=&quot;videoPlayer?.play()&quot;<br>          v-if=&quot;playing&quot;<br>          class=&quot;p-2 rounded-md bg-black&quot;<br>        &gt;<br>          &lt;PlayButton /&gt;<br>        &lt;/button&gt;<br>        &lt;button<br>          v-else<br>          @click=&quot;videoPlayer?.pause()&quot;<br>          class=&quot;p-2 rounded-md bg-red-700&quot;<br>        &gt;<br>          &lt;PauseButton /&gt;<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/section&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><p>In this scenario, the button for controls are not reactive as seen below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*zdXSPKyjZemoU_bz6CC4EA.gif" /></figure><p>This happened because the computed value is dependant on a non reactive value.</p><p>To get around this, we will use <a href="https://vueuse.org/">Vueuse library</a>. This library provides a long list of composables that adds reactivity to web browser API’s thereby making it easy to work with these API’s without having to re-invent the wheel.</p><p>To demonstrate we will be working with <strong>useMediaControls </strong>composable to fix this.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { ref, computed } from &quot;vue&quot;;<br>import { useMediaControls } from &quot;@vueuse/core&quot;;<br>import PlayButton from &quot;@/components/icons/PlayButton.vue&quot;;<br>import PauseButton from &quot;@/components/icons/PauseButton.vue&quot;;<br><br>const videoRef = ref();<br>const { playing: videoPlaying} = useMediaControls(videoRef, {<br>  src: &quot;/shrek_meets_donkey.mp4&quot;,<br>});<br>&lt;/script&gt;</pre><pre>&lt;template&gt;<br>  &lt;main class=&quot;md:min-h-screen md:p-5 p-2&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl&quot;&gt;Ouch, Mistakes. - Non reactive dependency.&lt;/h1&gt;<br><br>    &lt;section class=&quot;mt-16 relative&quot;&gt;<br>      &lt;video ref=&quot;videoRef&quot; class=&quot;mx-auto h-96&quot; /&gt;<br>      &lt;div<br>        v-auto-animate<br>        class=&quot;inline-flex gap-3 absolute top-[48%] right-[46%]&quot;<br>      &gt;<br>        &lt;button<br>          @click=&quot;videoRef?.play()&quot;<br>          v-if=&quot;!videoPlaying&quot;<br>          class=&quot;p-2 rounded-md bg-black&quot;<br>        &gt;<br>          &lt;PlayButton /&gt;<br>        &lt;/button&gt;<br>        &lt;button<br>          v-else<br>          @click=&quot;videoRef?.pause()&quot;<br>          class=&quot;p-2 rounded-md bg-red-700&quot;<br>        &gt;<br>          &lt;PauseButton /&gt;<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/section&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><p>As expected it works because the <strong>useMediaControls</strong> composable from Vueuse provides a reactive ref that can be used on the template to show different playing state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*br5uHlQee2Qs47N8saYZtg.gif" /></figure><p><strong>useMediaControls</strong> exposes other useful properties to give more control.</p><h3>Scenario — 3: Replacing reactive value</h3><p>Working with <strong>reactive</strong> API can be tricky because it requires caution so you don’t lose reactivity. Often developers replace entire object which leads to losing reactivity.</p><p>Below is a snippet of our template and script tag.</p><pre>&lt;template&gt;<br>  &lt;main class=&quot;md:min-h-screen md:p-5 p-2&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl&quot;&gt;Ouch, Mistakes - Replacing reactive value&lt;/h1&gt;<br><br>    &lt;section class=&quot;mt-16 relative&quot;&gt;<br>      &lt;button<br>        @click=&quot;loadMoreBirds&quot;<br>        class=&quot;px-4 py-1.5 absolute -top-16 right-5 bg-green-700 text-white&quot;<br>      &gt;<br>        Add more bird<br>      &lt;/button&gt;<br>      &lt;h1 class=&quot;text-3xl my-3&quot;&gt;Swift birds in Europe&lt;/h1&gt;<br>      &lt;pre&gt;{{ arrLength }}&lt;/pre&gt;<br><br>      &lt;h1 class=&quot;text-3xl my-3&quot; v-if=&quot;isLoading&quot;&gt;Loading...&lt;/h1&gt;<br>      &lt;ul v-else class=&quot;list-disc pl-3&quot;&gt;<br>        &lt;li v-for=&quot;item in swiftBirdsInEurope&quot; :key=&quot;item&quot;&gt;{{ item }}&lt;/li&gt;<br>      &lt;/ul&gt;<br>    &lt;/section&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { reactive, ref, computed } from &quot;vue&quot;;<br><br>const isLoading = ref(false);<br><br>let swiftBirdsInEurope = reactive([<br>  &quot;Alpine swift&quot;,<br>  &quot;Chimney swift&quot;,<br>  &quot;Pacific swift&quot;,<br>]);<br><br>const arrLength = computed(() =&gt; swiftBirdsInEurope.length)<br><br>function loadMoreBirds() {<br>  isLoading.value = true;<br>  swiftBirdsInEurope = [<br>    &quot;Common swift&quot;,<br>    &quot;Little swift&quot;,<br>    &quot;Pallid swift&quot;,<br>    &quot;White-rumped swift&quot;,<br>  ];<br>  setTimeout(() =&gt; (isLoading.value = false), 2000);<br>}<br>&lt;/script&gt;</pre><p>In the <strong>loadMoreBirds</strong> function the reactive value is updated with new list of birds. So far we don’t get an error and the UI gets updated as expected with the new set of birds. on inspection with Vue dev tools, the value is in fact updated but the computed value seem to remain the same.</p><figure><img alt="Result of the demo" src="https://cdn-images-1.medium.com/max/1024/1*x46o-_w7NPfcx017u-k2Pg.png" /><figcaption>Result of the demo</figcaption></figure><figure><img alt="Debugging with Vue dev tools." src="https://cdn-images-1.medium.com/max/1022/1*Y7-3IVLcAqZ18awirh5R5A.png" /><figcaption>Debugging with Vue dev tools.</figcaption></figure><p>This happened because we disconnected from reactivity when we updated the value by replacing with a new array.</p><p>This is a known limitation with <strong>reactive</strong> API. Reactive API also have limitation of not being able to hold primitive values.</p><p>Considering these down sides it’s recommended to use <strong>refs</strong>. Refs allow mutability while retaining the reactivity. They also store primitives which is an advantage.</p><h3><strong>In conclusion</strong></h3><p>Improper use of Vue’s APIs can result in unexpected bugs if not handled correctly. It’s essential to adhere to the appropriate API conventions for specific situations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10877bdc591d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚡️ Trending Vue 3 Libraries for 2024]]></title>
            <link>https://medium.com/@dimeji.ogunleye20/%EF%B8%8F-trending-vue-3-libraries-for-2024-97da75a21fcc?source=rss-8ef00c0ad30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/97da75a21fcc</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[2024-trends]]></category>
            <dc:creator><![CDATA[Dimeji Ogunleye]]></dc:creator>
            <pubDate>Mon, 29 Apr 2024 06:21:00 GMT</pubDate>
            <atom:updated>2024-04-29T06:21:00.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Vue Logo" src="https://cdn-images-1.medium.com/max/240/1*4XK2Pf6jeHDFHl1cvQ5n4Q.png" /></figure><p><a href="https://vuejs.org/"><strong>Vue Js</strong></a> is a progressive frontend framework created by <a href="https://github.com/yyx990803"><strong>Evan You</strong></a><strong> </strong>while working at Google Creative Labs. The first source code was released in July 2013.</p><p>For the past 10 years Vue Js has been a popular choice for developers for building web interfaces and the community is experiencing growth with an extensive array of libraries to improve developer experience and speed up development.</p><p>Without extensive conversation let’s review few trending libraries commonly utilised by Vue developers.</p><figure><img alt="Okay let’s roll." src="https://cdn-images-1.medium.com/max/360/1*FabZ8yE8F6eR9FMj4t_I2w.gif" /></figure><h3>1. TanStack Query</h3><figure><img alt="TanStack query logo." src="https://cdn-images-1.medium.com/max/200/1*VcUZEid0JlhLSuMoCI8PHA.png" /></figure><p><a href="https://tanstack.com/query/latest"><strong>TanStack Query</strong></a> is a library that helps to manage data fetching and data mutation. It helps to simplify data fetching while having access to numerous features such as caching and data-revalidation. It’s API are easy to use and it offers a great documentation.</p><p>Tanstack query is a great tool for data fetching as it improves user experience and also offers extensive capabilities with minimal code.</p><p>To get started, take the following steps;</p><ol><li>Depending on your project manager run any of these commands on the CLI within your project folder;</li></ol><pre>pnpm add @tanstack/vue-query<br>or<br>npm i @tanstack/vue-query<br>or<br>yarn add @tanstack/vue-query</pre><p>2. In your root file or entry file(main.ts) initialise the Vue query plugin and use it.</p><pre>//Import plugin<br>import { createApp } from &#39;vue&#39;<br>import { VueQueryPlugin } from &#39;@tanstack/vue-query&#39;<br>import App from &#39;./App.vue&#39;<br><br>const app = createApp(App)<br><br>//Instatiate plugin<br>app.use(VueQueryPlugin)<br>app.mount(&#39;#app&#39;)</pre><p>3. You can then use it in your components and pages.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { computed } from &#39;vue&#39;;<br>import { useQuery } from &#39;@tanstack/vue-query&#39;;<br>import axios from &#39;axios&#39;;<br><br>type Todo = {<br>  id: number<br>  userId: number<br>  title: string<br>  completed: boolean<br>}<br><br>const {<br>  isPending,<br>  isError,<br>  data: Todos<br>} = useQuery({<br>  queryKey: [&#39;todos&#39;],<br>  queryFn: () =&gt; axios(&#39;https://jsonplaceholder.typicode.com/todos&#39;)<br>})<br><br>const TodoList = computed(() =&gt; {<br>  return (Todos.value?.data as Array&lt;Todo&gt;) || []<br>})<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;main&gt;<br>    &lt;p v-if=&quot;isPending&quot;&gt;Loading...&lt;/p&gt;<br>    &lt;p v-else-if=&quot;isError&quot;&gt;An error occured. Please try again.&lt;/p&gt;<br>    &lt;ul v-else&gt;<br>      &lt;li v-for=&quot;(todo, index) in TodoList&quot; :key=&quot;index&quot;&gt;<br>        {{ todo?.title }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><p>Read more about available options from the <a href="https://tanstack.com/query/latest/docs/framework/vue/installation">docs</a>.</p><h3>2. Pinia</h3><figure><img alt="Pinia logo" src="https://cdn-images-1.medium.com/max/201/1*evQM4OtrXYniVF8dKwBOeQ.png" /></figure><p><a href="https://pinia.vuejs.org/"><strong>Pinia</strong></a> is a state management library gradually replacing Vuex due to its lightweight bundle size and ease of use. It doesn’t require a lot of configuration to start sharing state globally.</p><p>It offers great features with concise code and it’s production ready. To get started;</p><ol><li>Add as a dependency with your package manager.</li></ol><pre>npm install pinia<br>or<br>pnpm install pinia<br>or<br>yarn add pinia</pre><p>2. Register as a plugin at the entry file.</p><pre>import { createApp } from &#39;vue&#39;<br>import { createPinia } from &#39;pinia&#39;<br>import App from &#39;./App.vue&#39;<br><br>const pinia = createPinia()<br>const app = createApp(App)<br><br>app.use(pinia)<br>app.mount(&#39;#app&#39;)</pre><p>3. Create a store configuration.</p><pre>import { defineStore } from &#39;pinia&#39;<br>import { ref, computed } from &#39;vue&#39;<br><br>export const useUserActivity = defineStore(&#39;activity&#39;, () =&gt; {<br>  const isOnline = ref(true)<br>  const getCurrentState = computed(() =&gt; isOnline.value)<br>  function toggleActivity() {<br>    isOnline.value = !isOnline.value<br>  }<br><br>  return { isOnline, getCurrentState, toggleActivity }<br>})</pre><p>4. Consume global data in components, pages and composables.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { useUserActivity } from &#39;@/stores/activity&#39;<br><br>const activity = useUserActivity()<br>const { isOnline, toggleActivity } = activity<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;p v-if=&quot;isOnline&quot;&gt;User is online&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>For more reference read the <a href="https://pinia.vuejs.org/getting-started.html">docs</a>.</p><h3>3. Tailwind CSS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhwAoNMfTBmIkbYMaV8MVA.png" /></figure><p><a href="https://tailwindcss.com/"><strong>Tailwind</strong></a> is a utility-first CSS framework that enhances web development efficiency by providing set of predefined classes. These utilities classes are used directly on the HTML tree and it handles typography, colours, sizing, layout, e.t.c.</p><p>Tailwind offers great flexibility and extensibility while retaining the features of the framework without having to write custom CSS.</p><p>To get Tailwind installed in your Vue 3 project, follow these steps;</p><ol><li>Add using CLI with your package manager.</li></ol><pre>npm install -D tailwindcss postcss autoprefixer<br>or<br>pnpm install -D tailwindcss postcss autoprefixer</pre><p>2. Generate tailwind config file and post css file.</p><pre>npx tailwindcss init -p<br>or<br>pnpx tailwindcss init -p</pre><p>3. Configure Tailwind config file.</p><pre>/** @type {import(&#39;tailwindcss&#39;).Config} */<br>export default {<br>  content: [<br>    &quot;./index.html&quot;,<br>    &quot;./src/**/*.{vue,js,ts,jsx,tsx}&quot;,<br>  ],<br>  theme: {<br>    extend: {},<br>  },<br>  plugins: [],<br>}</pre><p>4. Add Tailwind directive to your CSS file.</p><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><p>5. Use the preset utility classes on html elements.</p><pre>&lt;template&gt;<br>  &lt;main class=&quot;mt-10&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl font-bold uppercase dark:text-white text-white&quot;&gt;<br>      Hello User.<br>    &lt;/h1&gt;<br>  &lt;/main&gt;<br>&lt;/template&gt;</pre><p>Tailwind also offers a great documentation, read more from the <a href="https://tailwindcss.com/docs/guides/vite#vue">docs.</a></p><h3>4. VueUse</h3><figure><img alt="VueUse" src="https://cdn-images-1.medium.com/max/300/1*G4wMXROx82xGLWKH2sp9OA.png" /></figure><p><a href="https://vueuse.org/"><strong>VueUse</strong></a> is a library that offers sets of Vue composition utilities to help improve developer experience and also help to streamline the process of writing boilerplate codes.</p><p>VueUse provides an extensive list of utility typed functions that are production ready and light-weight bundling size making it a trusted solution. To use VueUse in your project follow these steps;</p><ol><li>Install as a dependency.</li></ol><pre>npm i @vueuse/core<br>or<br>pnpm i @vueuse/core<br>or<br>yarn add @vueuse/core</pre><p>2. Import the preferred utility function in components, composables and pages and it’s ready for use.</p><pre>&lt;script setup lang=&quot;ts&quot;&gt;<br>import { useWindowSize, useBattery } from &#39;@vueuse/core&#39;<br><br>const { height, width } = useWindowSize()<br>const { charging, chargingTime, dischargingTime, level } = useBattery()<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;p&gt;Window Height:{{ height }} Window Width: {{ width }}&lt;/p&gt;<br>    &lt;p class=&quot;my-5 text-2xl text-green-300&quot;&gt;<br>      Battery level: {{ Math.round(level * 100) }} %<br>    &lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>You can refer to more utility functions on the <a href="https://vueuse.org/functions.html#category=Utilities">docs</a>.</p><h3>5. AutoAnimate</h3><figure><img alt="AutoAnimate Logo." src="https://cdn-images-1.medium.com/max/1024/1*V_dGLvPv-2rilzNkIT19kw.png" /></figure><p><a href="https://auto-animate.formkit.com/"><strong>AutoAnimate</strong></a> seamlessly enhances your web app with smooth transitions, requiring zero configuration for effortless integration. AutoAnimate adds animation to your project with minimal code.</p><p>To opt into the power of this library, follow these steps;</p><ol><li>Install as a dependency.</li></ol><pre>npm install @formkit/auto-animate<br>or<br>pnpm install @formkit/auto-animate<br>or<br>yarn add @formkit/auto-animate</pre><p>2. Register as a plugin at the entry file( main.ts )</p><pre>import { createApp } from &#39;vue&#39;<br>import { autoAnimatePlugin } from &#39;@formkit/auto-animate/vue&#39;<br>import App from &#39;./App.vue&#39;<br><br>const app = createApp(App)<br><br>app.use(autoAnimatePlugin)<br>app.mount(&#39;#app&#39;)</pre><p>3. Use the V-directive (v-auto-animate) on the intended parent element.</p><pre>&lt;div v-auto-animate class=&quot;flex justify-between items-center&quot;&gt;<br>   &lt;p v-if=&quot;toggle&quot;&gt;Peep&lt;/p&gt;<br>   &lt;button @click=&quot;toggle = !toggle&quot;&gt;Click me!&lt;/button&gt;<br> &lt;/div&gt;</pre><p>Refer to the <a href="https://auto-animate.formkit.com/#usage-vue">docs</a> for more information on configuration and options.</p><h3>6. Vue datepicker</h3><figure><img alt="Vue3 date picker" src="https://cdn-images-1.medium.com/max/300/1*J06IvHTtFbiOGtwPX4Ru4Q.png" /></figure><p><a href="https://vue3datepicker.com/"><strong>Vue datepicker</strong></a> provides a powerful and a lightweight component for seamless date interaction. Vue datepicker provides exceptional flexibility and customisation making it a perfect solution to handle date in your next project.</p><p>Installing and configuring Vue datepicker requires few steps, to get started take these steps;</p><ol><li>Install as a dependency.</li></ol><pre>npm install @vuepic/vue-datepicker<br>or<br>pnpm install @vuepic/vue-datepicker<br>or<br>yarn add @vuepic/vue-datepicker</pre><p>2. Import for usage.</p><ul><li><strong>Globally</strong></li></ul><pre>import { createApp } from &#39;vue&#39;<br>import VueDatePicker from &#39;@vuepic/vue-datepicker&#39;;<br>import &#39;./assets/main.css&#39;<br>import &#39;@vuepic/vue-datepicker/dist/main.css&#39;<br><br>const app = createApp(App)<br><br>//Global component<br>app.component(&#39;VueDatePicker&#39;, VueDatePicker);<br><br>app.mount(&#39;#app&#39;)</pre><pre>&lt;script setup&gt;<br>import { ref } from &#39;vue&#39;;<br><br>const date = ref();<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;VueDatePicker v-model=&quot;date&quot;&gt;&lt;/VueDatePicker&gt;<br>&lt;/template&gt;</pre><ul><li><strong>Locally</strong></li></ul><pre>&lt;script setup&gt;<br>import { ref } from &#39;vue&#39;;<br>import VueDatePicker from &#39;@vuepic/vue-datepicker&#39;;<br>import &#39;@vuepic/vue-datepicker/dist/main.css&#39;<br><br>const date = ref();<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;VueDatePicker v-model=&quot;date&quot;&gt;&lt;/VueDatePicker&gt;<br>&lt;/template&gt;</pre><p>Vue datepicker provides a range of options and customisation that can be explored on the <a href="https://vue3datepicker.com/props">docs</a>.</p><h3>Conclusion</h3><p>These featured libraries provide an efficient integration for Vue 3 and also Nuxt framework. They provide elegant and short syntax while still delivering high performance result. The set of features helps to avoid reinventing the wheel while still using the cool features they provide.</p><p>Below is a link to the demo source code used as demonstration.</p><p><a href="https://github.com/Kinglemar/trending-libraries-2024.git">GitHub - Kinglemar/trending-libraries-2024</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97da75a21fcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>