Common use cases
Practical recipes and patterns for working with hooks.js, based on real-world components.
Conditional Class Generation
Build CSS class strings based on multiple properties:
const transformHook = (rw) => {
const {
size,
variant,
isRounded,
hasShadow,
customClasses
} = rw.props;
const classes = [
// Size classes
size,
// Variant styles
variant === 'primary' && 'bg-blue-500 text-white',
variant === 'secondary' && 'bg-gray-200 text-gray-800',
// Optional modifiers
isRounded && 'rounded-lg',
hasShadow && 'shadow-md',
// User's custom classes
customClasses
]
.filter(Boolean)
.join(' ');
rw.setProps({ classes });
};
exports.transformHook = transformHook;Edit vs Preview Mode Branching
Show different content or behavior based on the current mode:
Responsive Image Handling
Generate responsive image sources based on theme breakpoints:
Template:
Root Element Configuration
Configure the wrapper element with dynamic tag, classes, and attributes:
Collection Data Transformation
Process and enhance collection data:
Filter Tags for Filtering
Set up data attributes for JavaScript-based filtering:
Alpine.js Integration
Set up Alpine.js data and bindings:
Last updated
Was this helpful?

