mergeProps is a utility function designed to merge multiple props objects. It's particularly useful for composing components with different prop sets or extending the functionality of existing components.
It is used internally by Bits UI components to merge the custom restProps you pass to a component with the props that Bits UI provides to the component.
Key Features
Merges multiple props objects
Chains event handlers with cancellation support
Combines class names
Merges style objects and strings
Chains non-event handler functions
Detailed Behavior
Event Handlers
Event handlers are chained in the order they're passed. If a handler calls event.preventDefault(), subsequent handlers in the chain are not executed.
If preventDefault() is called:
Since props2 called event.preventDefault(), props3's onclick handler will not be called.
Non-Event Handler Functions
Non-event handler functions are also chained, but without the ability to prevent subsequent functions from executing: