The mergeProps function is a utility function that can be used to merge props objects. It takes in two or more props objects and returns a new merged props object, which is useful for composing multiple components with different props.
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.
Event Handlers
mergeProps handles chaining of event handlers automatically in the order in which they are passed, and if a previous handler calls event.preventDefault(), the next handler in the chain will not be called.
Since props1 didn't call event.preventDefault(), props2 will still be called as normal.
Since props2 called event.preventDefault(), props3's onclick handler will not be called.
Non-Event Handler Functions
Functions that aren't event handlers are also chained together, but one can't cancel out the other since there isn't an event object to cancel.
Classes
mergeProps also handles the merging of classes using clsx. This means that you can pass in multiple classes as an array or string, and they will be merged together.
Styles
mergeProps also handles merging of style objects using style-to-object. You can pass in multiple style objects or style strings, and they will be gracefully merged together in the order they are passed.