0
0
Vueframework~20 mins

Functional components in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Functional Components Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Vue functional component render?

Consider this Vue 3 functional component using the Composition API. What will it render when used?

Vue
import { h } from 'vue'

const FunctionalComp = (props) => {
  return h('button', { type: 'button' }, `Click me ${props.name}`)
}

export default FunctionalComp
A<button type="button">Click me</button>
B<button>Click me Alice</button>
C<button type="button">Click me Alice</button>
D<div>Click me Alice</div>
Attempts:
2 left
💡 Hint

Look at the element type and attributes created by the h function.

state_output
intermediate
2:00remaining
What is the output of this functional component with reactive state?

Given this Vue 3 functional component using ref inside, what will it render initially?

Vue
import { ref, h } from 'vue'

const FunctionalCounter = () => {
  const count = ref(0)
  return h('div', `Count is ${count.value}`)
}

export default FunctionalCounter
A<div>Count is undefined</div>
B<div>Count is [object Object]</div>
C<div>Count is</div>
D<div>Count is 0</div>
Attempts:
2 left
💡 Hint

Remember to access the value of a ref with .value.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a Vue 3 functional component with props?

Choose the correct syntax for a Vue 3 functional component that accepts a title prop and renders it inside an h1 element.

Aconst MyFuncComp = (props) => h('h1', {}, props.title)
Bconst MyFuncComp = (props) => h('h1', props.title)
Cconst MyFuncComp = ({ title }) => h('h1', title)
Dconst MyFuncComp = (props) => h('h1', { innerHTML: props.title })
Attempts:
2 left
💡 Hint

Remember the h function signature: h(tag, props?, children?).

🔧 Debug
advanced
2:00remaining
Why does this Vue 3 functional component cause a runtime error?

Examine this functional component code. Why does it cause an error when rendered?

Vue
import { h } from 'vue'

const BrokenFuncComp = (props) => {
  return h('p', props.message.toUpperCase())
}

export default BrokenFuncComp
Ah() requires three arguments but only two are provided
Bprops.message is undefined causing a TypeError when calling toUpperCase()
CFunctional components cannot use props directly
DThe component must return a template string, not h() calls
Attempts:
2 left
💡 Hint

Check if props.message is always defined before calling string methods.

🧠 Conceptual
expert
2:00remaining
What is a key advantage of Vue 3 functional components over regular components?

Choose the best explanation of why you might use a functional component in Vue 3.

AThey have no reactive state or lifecycle, so they render faster and use less memory
BThey automatically cache all props and prevent re-renders
CThey allow using class-based syntax for better organization
DThey enable two-way binding without emitting events
Attempts:
2 left
💡 Hint

Think about what makes functional components lightweight compared to stateful ones.