When setup() returns a render function in Vue 3, accessing count.value inside it tracks the ref as a dependency. The increment() updates the ref, triggering a re-render where the new value '1' is read and displayed.
🧠 Conceptual
expert
2:00remaining
Which statement about Vue 3 render functions is true?
Choose the correct statement about Vue 3 render functions and their usage.
ARender functions must always use JSX syntax to work in Vue 3.
BRender functions can only return a single root element; multiple siblings cause errors.
CRender functions can return arrays of elements without wrapping them in a parent element.
DRender functions cannot access reactive state inside setup().
Attempts:
2 left
💡 Hint
Think about how Vue 3 handles fragments in render functions.
✗ Incorrect
Vue 3 supports fragments, so render functions can return arrays of elements without a wrapper. JSX is optional, and reactive state is accessible in setup.
Practice
(1/5)
1. What is the main purpose of the h function in Vue render functions?
easy
A. To create virtual DOM elements in JavaScript
B. To define CSS styles for components
C. To fetch data from an API
D. To register a new Vue component
Solution
Step 1: Understand the role of h in Vue
The h function is used to create virtual DOM nodes in Vue's render functions.
Step 2: Differentiate from other Vue tasks
Creating elements is different from styling, fetching data, or registering components.
Final Answer:
To create virtual DOM elements in JavaScript -> Option A
Quick Check:
h creates elements [OK]
Hint: Remember: h means 'hyperscript' for elements [OK]
Common Mistakes:
Confusing h with CSS or data fetching
Thinking h registers components
Assuming h is a lifecycle hook
2. Which of the following is the correct syntax for a simple Vue render function returning a <div> with text 'Hello'?
easy
A. render() { return h('div', { text: 'Hello' }) }
B. render() { return
Hello
}
C. render() { return h(div, 'Hello') }
D. render() { return h('div', 'Hello') }
Solution
Step 1: Check the correct use of h function
The h function takes a tag name as a string and children as the second argument.
Hello } uses JSX which is not default Vue render syntax. render() { return h(div, 'Hello') } misses quotes around 'div'. render() { return h('div', { text: 'Hello' }) } incorrectly uses an object with a text property.
Final Answer:
render() { return h('div', 'Hello') } -> Option D
Quick Check:
Tag as string + children string = correct syntax [OK]
Hint: Tag names must be strings in h calls [OK]
Common Mistakes:
Omitting quotes around tag names
Using JSX syntax without setup
Passing text inside an object instead of as child
3. What will the following Vue render function output?
A. Event handler key should be 'onClick' with capital C
B. Event handler key should be 'onclick' all lowercase
C. Event handler key should be 'onClick' but Vue expects 'onClick' as camelCase
D. Event handler key should be 'onClick' but Vue expects 'onClick' as 'onClick'
Solution
Step 1: Recall Vue event handler naming in render functions
Vue expects event handlers in render functions to use camelCase keys prefixed with 'on', like 'onClick'.
Step 2: Identify the incorrect key
The code uses 'onclick' with lowercase 'c', which Vue does not recognize as an event handler.
Final Answer:
Event handler key should be 'onClick' with capital C -> Option A
Quick Check:
Vue event keys are camelCase 'onClick' [OK]
Hint: Use camelCase event keys like 'onClick' in render functions [OK]
Common Mistakes:
Using lowercase event keys instead of camelCase
Confusing Vue event keys with JSX syntax
Assuming 'onclick' works like HTML attributes
5. How can you use a Vue render function to conditionally render a <span> with text 'Active' only if a signal isActive is true, otherwise render <span> with 'Inactive'?
hard
A. render() { if (isActive) return h('span', 'Active'); else return h('span', 'Inactive') }