Javascript is required
Weekly Vue News Logo Weekly Vue News
a { color: #42B883; text-decoration: none; } a:hover { color: #33a06f } .overflow-auto { overflow: auto } p {margin: 5px 0px} .ct-36e85c{color:#6A9955} .ct-8f9f80{color:#C8C8C8} .ct-ae5419{color:#808080} .ct-78eef5{color:#9CDCFE} .ct-0d8ec4{color:#B5CEA8} .ct-c2bbeb{color:#CE9178} .ct-c746e8{color:#DCDCAA} .ct-b1c360{color:#4FC1FF} .ct-220622{color:#569CD6} .ct-e8c10a{color:#C586C0} .ct-f3f815{color:#D4D4D4} FOLLOW_UP_PLACEHOLDER

#title Weekly Vue News #90 - Optimize Performance Using shallowRef #preview Ready for your weekly Vue & Nuxt dose?

View and discuss online, Weekly Vue News #90

Optimize Performance Using shallowRef

Vue School announced Vue.js Forge Episode 3!

Vue.js Forge is a hands-on, live coding online conference designed to deepen your knowledge of the Vue.js ecosystem and expose you to new and exciting tools and libraries rising in the ecosystem.

πŸ—“οΈ It’s all happening May 3-4!
πŸ€– At Vue.js Forge Episode 3 you will build an AI Social media generator!
πŸ‘¨πŸ»β€πŸ’» Live coding sessions guided by Daniel Roe, Daniel Kelly, Boudy de Geer and other industry leaders!
πŸ“£ This online conference is 100% FREE to attend!

Ready to team up with thousands of fellow Vue.js coders to build and learn together?

β†’ Register for Vue.js Forge Episode 3

Hi πŸ‘‹

Last week I uploaded the video for my remote talk at Vue.js Live and a short video for Vue.js Forge Episode 3. This week I plan to relax 🌴.

In this issue, I share a Vue Tip that can help you optimize performance using shallowRef. It also contains some of the best content from around the web, including articles, tutorials, and videos about Vue, Nuxt, and web development in general.

So sit back, relax, and get ready to dive into the world of Vue.js and Nuxt.js. Whether you're a developer, designer, or just someone who loves to learn about the latest tech, there's something here for you.

Have a lovely week β˜€οΈ


To support me:

Vue Tip: Optimize Performance Using shallowRef

shallowRef can be used to optimize the reactivity of your Vue application. As you might have guessed, shallowRef is a shallow version of ref().

Let's start by defining a counter state using shallowRef:

Component.vue
1<script setup lang="ts">
2import { shallowRef } from 'vue'
3
4const state = shallowRef({
5 count: 0,
6})
7</script>
8
9<template>
10 <span>Count: {{ state.count }}</span>
11</template>

Now let's try to modify the count value:

Component.vue
1<script setup lang="ts">
2import { shallowRef, watch } from 'vue'
3
4const state = shallowRef({
5 count: 0,
6})
7
8const increment = () => {
9 state.value.count = 2 // ⚠️ doesn't trigger change (watcher & UI update)
10}
11
12watch(state, (newState) => {
13 console.log('new state', newState)
14})
15</script>
16
17<template>
18 <span>Count: {{ state.count }}</span>
19 <button @click="increment">Increment count</button>
20</template>

If you click the "Increment count" button the counter in the UI is not updated and the watcher is not fired.

Unlike ref(), the inner value of a shallow ref is stored and exposed as-is, and will not be made deeply reactive. Only the .value access is reactive.

The reactivity is correctly triggered if we pass a complete new value to the .value property:

Component.vue
1<script setup lang="ts">
2import { shallowRef, watch } from 'vue'
3
4const state = shallowRef({
5 count: 0,
6})
7
8const setNewValue = () => {
9 state.value = { count: 2 } // triggers change
10}
11
12watch(state, (newState) => {
13 console.log('new state', newState)
14})
15</script>
16
17<template>
18 <span>Count: {{ state.count }}</span>
19 <button @click="setNewValue">Set new .value</button>
20</template>

shallowRef() is typically used for performance optimizations of large data structures, or integration with external state management systems.

Try it yourself in the following StackBlitz project:

⚑ Open DemoCurated Vue & Nuxt ContentπŸ“• Build Better Forms with Vue.js 3 Composition API: A Practical Guide

πŸ‘‰πŸ» Learn how to create custom form components with Vue.js 3 Composition API, including validation, submission handling and more.

digitalpatio.hashnode.dev
πŸ“• Nuxt vs VitePress vs Astro
πŸ‘‰πŸ» Timi compares Nuxt vs Vitepress vs Astro
πŸ‘‰πŸ» He focuses on what they are, their key features, and their ideal use cases.
medium.com
πŸ“Ή 7 Tips for Getting Started with Vue.js

πŸ‘‰πŸ» Seven known folks of the Vue Community shared their tips on getting started with Vue.js at Vue Amsterdam 2023

youtu.be
πŸ› οΈ Uno UI

πŸ‘‰πŸ» A Vue.js based UnoCSS UI library including a comprehensive collection of prebuilt, ready-to-use components.

onu.zyob.top
πŸ› οΈ VueUse v10.0.0
πŸ‘‰πŸ» createReusableTemplate
πŸ‘‰πŸ» createTemplatePromise
πŸ‘‰πŸ» useAnimate
πŸ‘‰πŸ» Improved tree-shaking
πŸ‘‰πŸ» and more...
github.com
Quote of the weekCurated Web Development ContentπŸ“• 10 TypeScript Tips & Tricks for Advanced Developers

πŸ‘‰πŸ» This article shows 10 lesser-known tips and tricks that will help you unlock TypeScript's full potential.

medium.com
πŸ“• 6 CSS snippets every front-end developer should know in 2023
πŸ‘‰πŸ» A container query
πŸ‘‰πŸ» Scroll snap
πŸ‘‰πŸ» Grid pile
πŸ‘‰πŸ» Quick circle
πŸ‘‰πŸ» Control variants with @layer
πŸ‘‰πŸ» Memorize less and reach more with logical properties
web.dev
πŸ“• JSON vs XML

πŸ‘‰πŸ» This article contains a transcript of a podcast featuring Douglas Crockford where he shares the story of JSON, his battles against XML, and more.

corecursive.com
πŸ› οΈ Tailwind Prettier Plugin

πŸ‘‰πŸ» A Prettier plugin for Tailwind CSS v3.0+ that automatically sorts classes based on their recommended class order

github.com
Comments? Join the discussion about this issue here.

Until next week,

Michael Hoffmann (Curator) Share via Facebook Twitter LinkedIn Unsubscribe from this newsletter
Holzapfelkreuther Str. 19, 81375 Munich, Germany
Weekly Vue News LogoWeekly newsletter that gives you high-quality tips and curated content about Vue & Nuxt.
I will never share any of your personal data.
Β© 2023 weekly-vue.news. All rights reserved.