#title Weekly Vue News #86 - When to Use Render Function #preview Ready for your weekly Vue & Nuxt dose?
When to Use Render Function
Hi π
Firstly, I would like to congratulate the recent Vue.js Live 2023 ticket raffle winners and express my gratitude to all who participated. Your support and enthusiasm are much appreciated, and I hope to continue offering engaging events and opportunities in the future.
In other news, I'll soon start preparing my talk for Vue.js Live 2023 conference.
Stay tuned for more updates, and thank you for being a valued part of our community.
Have a lovely week βοΈ
To support me:
- π Recommend the newsletter to your friends: it really helps!
- πΈ Sponsor the newsletter
- π§΅ Retweet the latest Twitter thread
- π¨ Reply to this email: feedback is welcome
There are very few cases where you should use a
Avoiding rendering functions results in code that is much easier to read and more accessible to other developers.
I think that render functions are a difficult-to-read mix of HTML and JavaScript.
Avoiding render functions is also the recommended approach in the
Vue recommends using templates to build applications in the vast majority of cases. However, there are situations where we need the full programmatic power of JavaScript. That's where we can use the render function.
Code Examples
Let's compare a simple example using the <template>
tag and render function. First the regular Vue component code:
1 <template>
2 <div class="wrapper">
3 <p class="any-class">Lorem Ipsum</p>
4 </div>
5 </template>
And this would be the equivalent using render function:
1 <script setup>
2 import { h } from 'vue'
3
4 const render = h(
5 'div', // type
6 { class: 'wrapper' }, // props
7 [
8 h(
9 'div',
10 {
11 class: 'any-class',
12 innerHTML: 'Lorem Ipsum',
13 },
14 []
15 ),
16 ] // children
17 )
18 </script>
19
20 <template>
21 <render />
22 </template>
Render Function Scenarios
Render functions are required when there is a necessity for harnessing the complete programmatic capabilities of JavaScript, such as gaining greater authority over how an application is rendered. Vue libraries development greatly benefits from render functions, which are also employed by a specific subset of developers.
ππ» Michael explains how to use Supabase and Github to log users in and out of a Nuxt 3 application.
masteringnuxt.comππ» We all know that Vue Router can be used to map routes to page components. |
ππ» Daniel shows how you can also use it to compose page layouts. |
ππ» tRPC is a library that makes it easy to build end-to-end typesafe APIs without code generation by leveraging the power of modern TypeScript.
www.youtube.comππ» Tejas learned Nuxt & Vue from Daniel Croe over a ~2 hour livestream.
www.youtube.comPreVue allows users to: |
ππ» Create components and preview their code |
ππ» Set up different routes and views |
ππ» Establish parent-child component relationships |
ππ» View application hierarchy in tree format |
ππ» Export the component architecture |
ππ» Technical article where Patrick creates a guide on how to find the right web frontend architecture that fits your specific quality goals.
www.workingsoftware.devππ» TypeScript has restructured its codebase to use ES modules. |
ππ» It results in smaller package sizes, quicker build times, and little disruption to end users. |
ππ» βThe main reason Iβve written this post though, is to send people to it when they ask why I use .flow or use margin, but also, I hope youβve seen how damn powerful CSS Custom Properties are.β
andy-bell.co.ukππ» Features a system font stack for every modern OS organized by typeface classification. |
ππ» The fonts are fast and do not require downloading, layout shifts, or flashes. |
ππ» They can be easily previewed with customizations. |
ππ» Elegant Console Logger for Node.js and Browser |
ππ» Easy to use |
ππ» Fancy output with fallback for minimal environments |
ππ» Pluggable reporters |
ππ» and more... |
Until next week,
Holzapfelkreuther Str. 19, 81375 Munich, Germany