stampit-org / react-stampit

A specialized stampit factory for React
131 stars 1 forks source link

Converting existing ES6 React Components to stamps #34

Closed josephfinlayson closed 9 years ago

josephfinlayson commented 9 years ago
import stamp from 'react-stampit/lib/utils/decorator';

class Component extends React.Component {

    render(){
        return (<div />)
    }
}

export default stamp(Component)

Is something like this possible? I'd like to convert my classes to stamps centrally without using decorators.

BerkeleyTrue commented 9 years ago

There is an undocumented feature to do this here

troutowicz commented 9 years ago

Well, it is documented... that function is the decorator function. It just so happens that it can also work as a regular function. So I guess in that sense it is undocumented. :)

BerkeleyTrue commented 9 years ago

Sorry about that, didn't see it. Yeah class decorators are just functions and can be used as such.

joshdmiller commented 9 years ago

I don't consider it undocumented either, but it's buried under advanced use cases. While I think it is better for new react-stampit people to think in the paradigm covered in the main readme, perhaps the "shortcut" decorator option should be at least mentioned there as well.

It might also be beneficial to document in the advanced use cases the plain function usage since decorators are not in wide use yet (babel still has them at stage 1).

troutowicz commented 9 years ago

I'd gladly accept a PR with those changes!

troutowicz commented 9 years ago

Closing, @josephfinlayson reopen if you still have questions.