Create-react-app: Stateless Functional Component is better

Created on 31 Jul 2016  路  1Comment  路  Source: facebook/create-react-app

/template/src/App.js is now using React Component Class, but this component is stateless.
So I think <App /> should be Stateless Functional Component.

I'm not good at English, here is a code example of my idea.

ASIS:

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

TOBE:

const App = () => (
  <div className="App">
    <div className="App-header">
      <img src={logo} className="App-logo" alt="logo" />
      <h2>Welcome to React</h2>
    </div>
    <p className="App-intro">
      To get started, edit <code>src/App.js</code> and save to reload.
    </p>
  </div>
);

If you agree this proposal, I will create a pull request!

Most helpful comment

Hi, we think most beginners would be confused seeing SFC there because we still don't use them as much in the documentation. Additionally they would not be sure how to add state or lifecycle methods. Moreover we would miss an opportunity to show that this project supports ES classes out of the box, so they would probably use createClass() syntax. Combined, these are the reasons we don't use SFC in this example.

>All comments

Hi, we think most beginners would be confused seeing SFC there because we still don't use them as much in the documentation. Additionally they would not be sure how to add state or lifecycle methods. Moreover we would miss an opportunity to show that this project supports ES classes out of the box, so they would probably use createClass() syntax. Combined, these are the reasons we don't use SFC in this example.

Was this page helpful?
0 / 5 - 0 ratings