Skip to content

Do not allow constructor in React components #26

Description

@koorchik
  1. Do not allow constuctor in React Components
  2. Force static propTypes proporty

I am not sure if this rules should be here. Maybe it is better to create a pull request to eslint-plugin-react

Considered bad:

class List extends React.Component {
    constructor(props) {
        super(props);   
    }

    handleClick() {
    
    }
    
    render() {
        <button onClick={this.handleClick} />
    }
}

Considered good:

class List extends React.Component {
    static propTypes = {};
    
    state = {};

    handleClick = () => {
    
    };
    
    render() {
        <button onClick={this.handleClick} />
    }
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions