Skip to content

Stateless Functional Component is better #304

Closed
@jyane

Description

@jyane

/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!

Activity

gaearon

gaearon commented on Jul 31, 2016

@gaearon
Contributor

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.

locked and limited conversation to collaborators on Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gaearon@jyane

        Issue actions

          Stateless Functional Component is better · Issue #304 · facebook/create-react-app