mantrajs / mantra-cli

Command line interface for building Meteor apps with Mantra
MIT License
135 stars 34 forks source link

Generating components, 2 possible results #59

Closed myyellowshoe closed 8 years ago

myyellowshoe commented 8 years ago

I noticed 2 ways components are built one way depending on how you generate them. I'm still a newb in this area I'll completely admit that, so there might be a perfectly good reason for this discrepancy. If its the case why is that? Whats the benefit of using one way over the other?

mantra g component core:messages

class Messages extends React.Component {
  render() {
    return (
      <div>
        Messages
      </div>
    );
  }
}

vs

mantra g container core:messages Generates container and following component

const Messages = () => (
  <div>
    Messages
  </div>
);
sungwoncho commented 8 years ago

Contrary to your description, both mantra g component core:messages and mantra g container core:messages will generate a component looking like the following:

import React from 'react';

const Messages = () => (
  <div>
    Messages
  </div>
);

export default Messages;

To generate the component of the first form in your question, you need to use --use-class option. See README.

The distinction between the two types of components is whether they have states or not. The first may have states while the latter cannot. Avoiding the first when you can is considered a good practice. You can read more here.

sungwoncho commented 8 years ago

Please re-open if there is an issue. A good place to discuss Mantra related topics is https://talk.mantrajs.com/.

myyellowshoe commented 8 years ago

Snap. You're right. My bad on that. Appreciate the link I'll check that out.