layershifter / babel-plugin-transform-react-handled-props

Generates handledProps from defaultProps and propTypes during the build :sparkles:
MIT License
19 stars 4 forks source link

Should support spread operator in propTypes objects #77

Open patricklafrance opened 4 years ago

patricklafrance commented 4 years ago

Hi,

I believe this plugin should support using spread operators in the propTypes object.

There is a test fixture for this case: https://github.com/layershifter/babel-plugin-transform-react-handled-props/tree/master/test/fixtures/spread

But the expected result seem wrong to me. I believe handledProps should include the active prop meaning:

Example.handledProps = ["children", "className", "active"]`

Thank you,

Patrick

layershifter commented 4 years ago

@patricklafrance hey 👋

It's also what I expect 😺 But, it's to hard to do it without runtime execution especially if propTypes will come from other files.

patricklafrance commented 4 years ago

Hi @layershifter

Maybe a first step would be to support the spread operator for local variables?

Something like this seems to do it: https://github.com/reactjs/react-docgen/pull/415/files#diff-b35f78065f9458034d34daff3f3a3a11R113

Patrick

patricklafrance commented 4 years ago

I ended up rewriting my code to hooks and I don't need the plugin anymore. Feel free to close this issue if you feel it doesn't worth investing time in this.