Problem: I have a React component with optional props that should only be...


Problem: I have a React component with optional props that should only be used together.

Solution: I unify the props into a single prop that accepts an object.

#react

Another good option to consider is to use the "slot" pattern. (see pic)

The tradeoff: The consumer has more power to put whatever they want in the slot. Depending on your intention, that may not be desirable. The approach I've shown above enforces consistency.

View original on X