ilyalesik / react-overrides

Pass props to internal elements of React component
28 stars 1 forks source link

babel-plugin-macros version? #1

Open tlrobinson opened 5 years ago

tlrobinson commented 5 years ago

Could this be implemented using babel-plugin-macros, which will work out of the box with create-react-app?

You'd probably have to do something like:

import overridable from 'react-overrides/overridable.macro'

export const CommonButton = overridable(props => (
    <Container onClick={props.onClick}>
        <Text>{props.children}</Text>
    </Container>
));

But then maybe you could leave off the {...o}, which I assume is there to tell the plugin which components it should be applied to?

ilyalesik commented 5 years ago

@tlrobinson It's an interesting idea.

But then maybe you could leave off the {...o}, which I assume is there to tell the plugin which components it should be applied to?

Yeah, {...o} tell the plugin that element is overradable. But we can just make all elements inside component overridable.

Also, plugin provide access to individual props: <Container className={c("button", o.className)}. I don't know, as it is possible to implement with babel-plugin-macros.