Performance: Render function syntax
This affects how Vue components are rendered and how efficiently the virtual DOM updates happen.
import { h } from 'vue' export default { data() { return { message: 'Hello', count: 0 } }, render() { return h('div', `${this.message} ${this.count}`) } }
import { h } from 'vue' export default { data() { return { message: 'Hello', count: 0 } }, render() { return h('div', this.message + ' ' + this.count) } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| String concatenation in render | Minimal | 1 per update | Low to medium | [!] OK |
| Template literals in render | Minimal | 1 per update | Low | [OK] Good |
h function in Vue render functions?h in Vueh function is used to create virtual DOM nodes in Vue's render functions.h creates elements [OK]h means 'hyperscript' for elements [OK]h with CSS or data fetchingh registers componentsh is a lifecycle hook<div> with text 'Hello'?h functionh function takes a tag name as a string and children as the second argument.h('div', 'Hello'). render() { return h calls [OK]render() { return h('ul', [ h('li', 'One'), h('li', 'Two') ]) }h callsh creates a ul element. The children are an array of two li elements created by inner h calls.ul with two li children: 'One' and 'Two'.h creates nested elements [OK]h create multiple children elements [OK]h returns elements, not stringsrender() { return h('button', { onclick: () => alert('Clicked') }, 'Click me') }<span> with text 'Active' only if a signal isActive is true, otherwise render <span> with 'Inactive'?isActive() gets the boolean.h sets the text child based on isActive().isActive directly without calling, which is incorrect for signals. render() { return h('span', { text: isActive ? 'Active' : 'Inactive' }) } incorrectly passes text inside an object. render() { return h('span', isActive ? 'Active' : 'Inactive') } uses isActive without calling.Pass the test and this pattern moves unknown