| Ok, fair enough. It was a drive by shooting of a comment. So here’s a more considered criticism. There’s already a way to overwrite props in react. Just use props. If you need to expose the native API of the underlying element, do this (does HN format code?)... ```
const {foo, ...native} = props; <label {...native}>
<p>{foo}</p>
</label> ``` Combine that with default props and you’re good to go. There’s already a way to allow components to take multiple types of children. ```
<Select render={ blah => {
return <CustomOption>{blah}</CustomOption>
}} />
``` And there’s already a multitude of ways to adapt styles based on props, the most obvious of which is StyledComponents. In addition, this highlevel config is brittle. It means parents must be coupled to their children, and children coupled to their parents. And where does this config end? How deep does the nesting of this configuration go? Here’s my opinion; if you think you need this sort of configuration to properly wrangle your UI, then you’ve failed to grasp the point of React and the true power of composition. React components are just functions. Preferably pure functions. Once you strip away the JSX, you should be left with something that resembles functional programming (albeit taken to an extreme thanks to JSX’s goal of emulating HTML). Props are parameters. We’ve all come across code where functions take complex and convoluted objects as arguments that trigger an explosion of calls that are near impossible to track or reason about. This override solution is the first step in towards turning React into the kind of tool that it usurped. It has the stench of ExtJs and it’s ilk. This “solution” was created by people who believe all problems are better solved by abstraction. As programmers, our time is spent on the edge cases. Our text book prefect algorithms and mathematically sound functions are exposed as frauds the second they’re exposed to user input. Our carefully crafted UI libraries fall to pieces when the designers choose to break their own rules. For configuration to work, it requires god level foresight and will eventually become Turing complete in itself. Config is for the birds. Declarative code has always been the answer. |
It actually does everything you propose.
For render props, the BaseWeb API is not <Select renderDropdown={...} renderArrow={...} renderLabel={...} /> but it's collapsed under a single prop overrides={{ Dropdown: { component: {...} } ... }} naming convention. This "map" includes (and gives you access) to every single subcomponent.
The same goes for "adapting styles based on props".
BaseWeb uses exactly same patterns and techniques that you mention. The difference is the naming consistency and uniformity across all components. Instead of "littering" the top level API, we have a single prop "overrides" and instead of deciding what should and shouldn't be customizable, everything is customizable. Again, without a need to keep adding new top level props.