react-pure-to-class icon indicating copy to clipboard operation
react-pure-to-class copied to clipboard

Class to Pure

Open idahogurl opened this issue 6 years ago • 4 comments

Thank you for this plugin! It's awesome. I have the additional issue of where a component is written as a class but should be a pure function. Would you consider adding a reverse refactor?

idahogurl avatar Jul 13 '18 17:07 idahogurl

I found react-codemod from Facebook has that transformation in the transforms/PureComponent file. so all would need to do is require that package and require the PureComponent file.

idahogurl avatar Jul 13 '18 19:07 idahogurl

Hey! Yes, I know about that codemod. I was thinking about reverse transformation myself a few months ago, but consequently forgot about it =) I'll see if I can incorporate their code.

angryobject avatar Jul 14 '18 15:07 angryobject

So, I tried incorporating the codemod, at it works, but it doesnt support all the options that PureToClass has, so you can't transform the same piece of code back and forth which is what i'd like to. It only transforms if you extend from React.Component and doens't transform if you have anything in you class besides render method, even an empty constructor like so:

constructor(props) {
  super(props);
}

Seems like i'll have to either modify their code or write my own. We'll try asap.

angryobject avatar Oct 06 '18 14:10 angryobject

Or you can try this plugin https://marketplace.visualstudio.com/items?itemName=wix.glean

FDiskas avatar May 14 '19 13:05 FDiskas