A functional component is a simple Vue component that is stateless and instanceless. It is just a function that returns virtual DOM nodes and does not have its own reactive data or lifecycle hooks.
Click to reveal answer
intermediate
How do you define a functional component in Vue 3?
You define a functional component by creating a function that returns the render output using JSX or the h() function.
Click to reveal answer
beginner
Why might you choose a functional component over a regular component?
Functional components are faster because they do not have reactive state or lifecycle overhead. They are useful for simple UI pieces that only depend on props and do not need internal state or side effects.
Click to reveal answer
beginner
Can functional components in Vue have reactive state or lifecycle hooks?
No, functional components do not have reactive state or lifecycle hooks. They are purely presentational and rely only on props to render their output.
Click to reveal answer
beginner
How do you pass props to a functional component in Vue?
You pass props to a functional component the same way as regular components. The props are received as the first argument in the functional component function.
Click to reveal answer
What is a key characteristic of a Vue functional component?
AIt has no reactive state or lifecycle hooks
BIt must use class-based syntax
CIt always manages its own state
DIt cannot receive props
✗ Incorrect
Functional components are stateless and instanceless, so they do not have reactive state or lifecycle hooks.
How do you define a functional component in Vue 3?
AExport a function that returns the render output
BUse the 'data' option to define state
CUse the 'mounted' lifecycle hook
DDefine a class component
✗ Incorrect
Functional components are defined by exporting a function that returns the render output.
Which of these is NOT true about Vue functional components?
AThey improve performance by skipping lifecycle hooks
BThey can have internal reactive state
CThey receive props as arguments
DThey are useful for simple UI pieces
✗ Incorrect
Functional components do not have internal reactive state.
How do you pass props to a functional component in Vue?
AProps cannot be passed to functional components
BUsing the 'data' option
CUsing the 'methods' option
DAs the first argument to the component function
✗ Incorrect
Props are passed as the first argument to the functional component function.
Which Vue feature is NOT available in functional components?
ARender functions
BProps
CLifecycle hooks
DPassing slots
✗ Incorrect
Functional components do not have lifecycle hooks.
Explain what a functional component is in Vue and when you might use it.
Think about components that just show data without changing it.
You got /5 concepts.
Describe how to create a functional component in Vue 3.
Focus on the function and what it returns.
You got /4 concepts.
Practice
(1/5)
1. What is a key characteristic of a functional component in Vue?
easy
A. It manages its own state and lifecycle hooks.
B. It requires a template section to render.
C. It can only be used with class-based components.
D. It is stateless and has no reactive data.
Solution
Step 1: Understand functional component basics
Functional components in Vue are designed to be simple and stateless, meaning they do not hold reactive data or manage lifecycle hooks.
Step 2: Compare options with definition
It is stateless and has no reactive data. correctly states that functional components are stateless. Options A, C, and D describe features not applicable to functional components.
Final Answer:
It is stateless and has no reactive data. -> Option D
Quick Check:
Functional component = stateless [OK]
Hint: Functional components do not hold state or lifecycle hooks [OK]
Common Mistakes:
Thinking functional components have reactive state
Assuming they use lifecycle hooks
Confusing with class-based components
2. Which of the following is the correct syntax to define a functional component using the <script setup> syntax in Vue 3?
easy
A. <script setup functional>\nexport default { props: ['text'] }\n</script>
B. <script setup>\nimport { h } from 'vue'\nconst MyFuncComp = (props) => h('div', props.text)\n</script>
C. <script setup>\nexport default { functional: true, props: ['text'] }\n</script>
D. <script setup>\nconst MyFuncComp = (props) => <div>{props.text}</div>\n</script>
Solution
Step 1: Recall Vue 3 functional component syntax
In Vue 3 with <script setup>, functional components can be defined as functions returning VNodes using the h helper.
Step 2: Analyze each option
<script setup>\nimport { h } from 'vue'\nconst MyFuncComp = (props) => h('div', props.text)\n</script> correctly defines a functional component returning a div with text using h. <script setup>\nconst MyFuncComp = (props) => <div>{props.text}</div>\n</script> uses JSX-like syntax which is not default in Vue. Options B and C use options API syntax incorrectly inside <script setup>.
Final Answer:
<script setup>
import { h } from 'vue'
const MyFuncComp = (props) => h('div', props.text)
</script> -> Option B
Quick Check:
Functional component = function returning VNode with h() [OK]
Hint: Use function returning h() in
Common Mistakes:
Using options API inside
Trying to use JSX without setup
Missing h() helper for rendering
3. Given this functional component code, what will be rendered?
A. Using JSX syntax without proper setup causes an error.
B. Missing props declaration in options API.
C. Functional components cannot return elements.
D. The function should not use return statement.
Solution
Step 1: Check syntax used in functional component
The code uses JSX-like syntax (<button>{props.label}</button>) inside a function without JSX support configured.
Step 2: Understand Vue default rendering
Vue requires using h() helper or templates unless JSX is set up. Without JSX setup, this causes a syntax error.
Final Answer:
Using JSX syntax without proper setup causes an error. -> Option A
Quick Check:
JSX needs setup; otherwise use h() or template [OK]
Hint: JSX syntax requires special setup; otherwise use h() [OK]
Common Mistakes:
Assuming JSX works by default
Forgetting to import h()
Thinking return statement is disallowed
5. You want to create a functional component that renders a list of items passed as a prop. Which code correctly implements this in Vue 3 using <script setup> and the h function?
hard
A. <script setup>
import { h } from 'vue'
const ItemList = (props) => h('ul', props.items.map(item => h('li', item)))
</script>
B. <script setup>
const ItemList = { functional: true, props: ['items'], template: '<ul><li v-for="item in items">{{ item }}</li></ul>' }
</script>