Prop Getter Arguments: Customization Points
What you'll learn: How to allow users to pass customization options into prop getter functions while keeping smart defaults intact.
The Core Idea
So far, your prop getters return fixed prop objects. But what if users need slight variations based on context? By accepting arguments, prop getters become customization points—users can pass in specific values to modify behavior while the getter still handles all the complex defaults.
This is like ordering a coffee with customizations: the barista knows the standard recipe (your getter's defaults), but you can say "extra hot" or "oat milk" to adjust specific aspects without redoing the entire drink from scratch.
How It Works
Instead of calling getInputProps() with no arguments, users can pass an object:
function useCombobox() {
// Internal state and logic
const isOpen = /* ... */;
const getInputProps = (options = {}) => {
const { disabled = false, placeholder = "Search..." } = options;
return {
role: "combobox",
"aria-expanded": isOpen,
"aria-autocomplete": "list",
disabled,
placeholder,
onKeyDown: handleKeyDown,
onChange: handleChange
};
};
return { getInputProps };
}
// User can customize specific props
<input {...getInputProps({ disabled: true, placeholder: "Type to search" })} />
The getter merges user-provided customizations with library defaults. The library still controls critical ARIA attributes and handlers, but grants flexibility where it makes sense.
Common Customization Points
- Visual options:
disabled,placeholder,className - Behavior flags:
preventScroll,closeOnSelect - Type refinement:
type="email"for specific input types
Key Takeaway: Prop getter arguments transform getters into flexible APIs—users customize what they need while the library maintains complex default behavior they don't want to reimplement.