Consider this Vue 3 functional component using the Composition API. What will it render when used?
import { h } from 'vue' const FunctionalComp = (props) => { return h('button', { type: 'button' }, `Click me ${props.name}`) } export default FunctionalComp
Look at the element type and attributes created by the h function.
The functional component returns a button element with type="button" and text including the name prop. So option C matches exactly.
Given this Vue 3 functional component using ref inside, what will it render initially?
import { ref, h } from 'vue' const FunctionalCounter = () => { const count = ref(0) return h('div', `Count is ${count.value}`) } export default FunctionalCounter
Remember to access the value of a ref with .value.
The count is a ref initialized to 0. Accessing count.value gives 0, so the rendered text is 'Count is 0'.
Choose the correct syntax for a Vue 3 functional component that accepts a title prop and renders it inside an h1 element.
Remember the h function signature: h(tag, props?, children?).
Option A correctly passes an empty props object and the title as children text. Option A and B pass the title as props, which is incorrect. Option A uses innerHTML which is not recommended here.
Examine this functional component code. Why does it cause an error when rendered?
import { h } from 'vue' const BrokenFuncComp = (props) => { return h('p', props.message.toUpperCase()) } export default BrokenFuncComp
Check if props.message is always defined before calling string methods.
If props.message is missing or undefined, calling toUpperCase() causes a TypeError. The h function usage is correct.
Choose the best explanation of why you might use a functional component in Vue 3.
Think about what makes functional components lightweight compared to stateful ones.
Functional components are stateless and have no lifecycle hooks, so they are simpler and faster to render. Other options describe features not related to functional components.