Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some codes needs enhancement! #1337

Closed
xgqfrms-GitHub opened this issue Mar 12, 2017 · 3 comments
Closed

some codes needs enhancement! #1337

xgqfrms-GitHub opened this issue Mar 12, 2017 · 3 comments

Comments

@xgqfrms-GitHub
Copy link

xgqfrms-GitHub commented Mar 12, 2017

old

// bad
function SFC({ foo, bar, children }) {
  return <div>{foo}{bar}{children}</div>;
}
SFC.propTypes = {
  foo: PropTypes.number.isRequired,
  bar: PropTypes.string,
  children: PropTypes.node,
};

// not too good
function SFC({ foo, bar }) {
  return <div>{foo}{bar}</div>;
}
SFC.propTypes = {
  foo: PropTypes.number.isRequired,
  bar: PropTypes.string,
  children: PropTypes.node,
};
SFC.defaultProps = {
  bar: '',
  children: null,
};

new

// bad
function SFC({ foo, bar, children }) {
    return <div>{foo}{bar}{children}</div>;
}
SFC.propTypes = {
    foo: PropTypes.number.isRequired,
    bar: PropTypes.string,
    children: PropTypes.node,
};

// good
function SFC({ foo, bar, children }) {
    return <div>{foo}{bar}{children}</div>;
}
SFC.propTypes = {
    foo: PropTypes.number.isRequired,
    bar: PropTypes.string,
    children: PropTypes.node,
};
SFC.defaultProps = {
    bar: '',
    children: null,
};
@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Mar 12, 2017

one more !

// bad
React.createClass({
    _onClickSubmit() {
        // do stuff
    },
    // other stuff
});

// not too good
class extends React.Component {
    onClickSubmit() {
        // do stuff
    }
    // other stuff
}

it solud be like this,

// bad
React.createClass({
    _onClickSubmit() {
        // do stuff
    },
    // other stuff
});

// good
React.createClass({
    onClickSubmit() {
        // do stuff
    },
    // other stuff
});

or this.

// bad
class extends React.Component {
    _onClickSubmit() {
        // do stuff
    },
    // other stuff
};

// very good & ES6
class extends React.Component {
    onClickSubmit() {
        // do stuff
    }
    // other stuff
}

@ljharb
Copy link
Collaborator

ljharb commented Mar 12, 2017

I'm confused - in your latter example, you seem to be referring to the "Do not use underscore prefix for internal methods of a React component." section of https://github.com/airbnb/javascript/tree/master/react - where React.createClass is a bad example (as it always is; it's deprecated) and an ES6 class-based component is a good example. Instead providing long amounts of code in an issue, could you either submit a pull request (so we can see diifs), or in the issue, talk only about the specific changes?

I do see what you mean in the first example; please feel free to submit a PR to fix that.

(I've also updated your comments to remove the unnecessary markdown headings (#), since large bold text adds noise and makes things harder to read)

@xgqfrms-GitHub
Copy link
Author

  1. SFC({ foo, bar, children }) !== SFC({ foo, bar, children })

  2. class extends React.Component !== React.createClass

what's I mean is that both demos should have the same condition(e.g parameters) for compare!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants