Default Behavior with Override Escape Hatches
What you'll learn: How to design components that work great out-of-the-box while letting consumers override behavior when they need more control.
The Core Idea
This pattern combines the best of both worlds: your component provides sensible defaults that handle 95% of use cases automatically, but exposes "escape hatches" — optional props that let consumers override specific behaviors when needed.
Think of it like a smart thermostat: it automatically maintains a comfortable temperature (default behavior), but you can manually adjust it anytime (escape hatch). Most users never touch the controls, but power users appreciate having them.
How It Works in Practice
You've already seen this pattern emerge from controlled/uncontrolled patterns and render props. Now we generalize it:
The default: Component handles behavior internally.
The escape hatch: Optional prop that overrides the default.
function SearchBox({ onSearch, renderResults }) {
const [query, setQuery] = useState('');
const [results, setResults] = useState([]);
// Default behavior: fetch results automatically
useEffect(() => {
if (!onSearch) {
fetchDefaultResults(query).then(setResults);
}
}, [query, onSearch]);
// Escape hatch: consumer controls search logic
const handleSearch = onSearch || (() => {});
// Default rendering, but allow override
const resultsDisplay = renderResults
? renderResults(results)
: <DefaultResultsList items={results} />;
return (
<div>
<input value={query} onChange={e => setQuery(e.target.value)} />
{resultsDisplay}
</div>
);
}
The component works perfectly without any props, but consumers can override search logic or result rendering when their use case demands it.
Key Takeaway: Design components with smart defaults that handle common cases automatically, but expose optional props as escape hatches for customization — giving consumers progressive control without sacrificing ease of use.