Challenge - 5 Problems
Block Attributes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does the attribute default value affect block rendering?
Consider a WordPress block with an attribute defined as
color: { type: 'string', default: 'blue' }. What will be the rendered color if the user does not change this attribute?Attempts:
2 left
💡 Hint
Think about what 'default' means for block attributes in WordPress.
✗ Incorrect
The default value in block attributes is used when the user has not set a value. This ensures the block has a predictable initial state.
📝 Syntax
intermediate1:30remaining
Identify the correct attribute declaration syntax
Which of the following is the correct way to declare a block attribute for a string named 'title' with no default value?
Attempts:
2 left
💡 Hint
Attributes are objects with type and optionally default properties.
✗ Incorrect
The correct syntax uses an object with a type property. Option C correctly declares the attribute.
❓ state_output
advanced2:00remaining
What is the output when a block control updates an attribute?
Given a block with an attribute
count: { type: 'number', default: 0 } and a control that increments count on button click, what will be the value of count after clicking the button three times starting from initial render?Wordpress
const { useState } = wp.element;
function MyBlock({ attributes, setAttributes }) {
const { count } = attributes;
return (
<button onClick={() => setAttributes({ count: count + 1 })}>
Count: {count}
</button>
);
}Attempts:
2 left
💡 Hint
Each click increases the count by 1 starting from the default.
✗ Incorrect
The attribute count starts at 0. Each button click adds 1, so after 3 clicks, count is 3.
🔧 Debug
advanced2:30remaining
Why does this block attribute not update correctly?
A block attribute
text: { type: 'string', default: '' } is controlled by a text input. The input's onChange handler calls setAttributes({ text: event.target.value }). However, the block does not update when typing. What is the likely cause?Wordpress
function MyBlock({ attributes, setAttributes }) {
const { text } = attributes;
return (
<input
type="text"
value={text}
onChange={(event) => setAttributes({ text: event.target.value })}
/>
);
}Attempts:
2 left
💡 Hint
Check if the attribute is properly declared in the block registration.
✗ Incorrect
If the attribute is not declared in the block's attributes object, setAttributes will not update it, so the input stays unchanged.
🧠 Conceptual
expert3:00remaining
How do block controls and attributes interact to maintain state?
In WordPress block development, which statement best describes the relationship between block attributes and controls?
Attempts:
2 left
💡 Hint
Think about how user input changes block data and how that data affects the block.
✗ Incorrect
Controls are UI elements that let users change attribute values. Attributes hold the block's data and determine how it renders.