Challenge - 5 Problems
JSX Vue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Vue JSX component render?
Consider this Vue 3 component using JSX syntax. What will it render in the browser?
Vue
import { defineComponent } from 'vue'; export default defineComponent({ setup() { const message = 'Hello from JSX!'; return () => <div><h1>{message}</h1><p>{message.length}</p></div>; } });
Attempts:
2 left
💡 Hint
Remember JSX expressions inside curly braces evaluate JavaScript expressions.
✗ Incorrect
The JSX renders the string stored in 'message' inside the
. The
shows the length of that string, which is 16 characters.
📝 Syntax
intermediate2:00remaining
Which JSX syntax is correct for binding a click event in Vue?
In Vue JSX, how do you correctly bind a click event handler named 'handleClick' to a button element?
Attempts:
2 left
💡 Hint
Vue JSX uses camelCase event names similar to React.
✗ Incorrect
In Vue JSX, event handlers use camelCase like 'onClick'. The value is a function reference or inline function. Option A correctly binds the handler.
🔧 Debug
advanced2:00remaining
Why does this Vue JSX component throw an error?
This Vue component using JSX throws an error when rendering. What is the cause?
Vue
import { defineComponent, ref } from 'vue'; export default defineComponent({ setup() { const count = ref(0); return () => <button onClick={count++}>Count: {count.value}</button>; } });
Attempts:
2 left
💡 Hint
Remember that Vue refs are objects and you must update their .value property.
✗ Incorrect
The onClick handler uses 'count++' which tries to increment the ref object itself, causing an error. The correct way is to update count.value inside a function.
❓ lifecycle
advanced2:00remaining
How to use Vue lifecycle hooks inside a JSX component?
Which is the correct way to run code when a Vue JSX component mounts?
Vue
import { defineComponent, onMounted } from 'vue'; export default defineComponent({ setup() { onMounted(() => { console.log('Mounted!'); }); return () => <div>Check console</div>; } });
Attempts:
2 left
💡 Hint
Vue 3 uses composition API lifecycle hooks inside setup.
✗ Incorrect
In Vue 3 with JSX, lifecycle hooks like onMounted are called inside setup. Option B correctly uses onMounted to run code after mounting.
❓ state_output
expert2:00remaining
What is the output after clicking the button twice?
Given this Vue JSX component, what will be the displayed count after clicking the button two times?
Vue
import { defineComponent, ref } from 'vue'; export default defineComponent({ setup() { const count = ref(0); const increment = () => { count.value += 1; count.value += 1; }; return () => <button onClick={increment}>Count: {count.value}</button>; } });
Attempts:
2 left
💡 Hint
Each click runs increment which adds 2 to count.value.
✗ Incorrect
Each click adds 2 to count.value. After two clicks, count.value is 4, so the button shows 'Count: 4'.