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

Inconsistent Code Style Enforcement in React Components #2995

Open
bitcooker opened this issue Jun 7, 2024 · 4 comments
Open

Inconsistent Code Style Enforcement in React Components #2995

bitcooker opened this issue Jun 7, 2024 · 4 comments

Comments

@bitcooker
Copy link

There seems be notable inconsistencies in how code style rules are applied within the React components section.

  • Method Ordering:
    There are discrepancies in the ordering of lifecycle methods and custom methods in the React components.
    For example, some components list componentDidMount before componentWillUnmount, while others do not follow this order.
// Example 1
class MyComponent extends React.Component {
  componentDidMount() {
    // logic
  }
  
  componentWillUnmount() {
    // logic
  }
  
  customMethod() {
    // logic
  }
}

// Example 2
class AnotherComponent extends React.Component {
  customMethod() {
    // logic
  }
  
  componentWillUnmount() {
    // logic
  }
  
  componentDidMount() {
    // logic
  }
}
  • State Initialization:
    The initialization of state in constructor methods varies across different examples. Some components use direct state initialization within the constructor, while others use class property syntax.
// Example 1
class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }
}

// Example 2
class MyComponent extends React.Component {
  state = {
    count: 0
  };
}
  • Event Handler Bindings:
    Inconsistent usage of binding event handlers in the constructor versus using class properties to define arrow functions.
// Example 1
class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    // logic
  }
}

// Example 2
class MyComponent extends React.Component {
  handleClick = () => {
    // logic
  }
}
@Medha170
Copy link

Medha170 commented Aug 1, 2024

Can you assign this issue to me?

@ljharb
Copy link
Collaborator

ljharb commented Aug 1, 2024

@Medha170 no, because that's not how open source works. issues don't get assigned, you just make a PR.

@prateekbisht23
Copy link

@bitcooker Would you mind specifying the path to the code you mentioned!?

@sanks011
Copy link

@bitcooker can you specify like where the changes should be made? like the file path

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

No branches or pull requests

5 participants