DEV Community

Nwanguma Victor
Nwanguma Victor

Posted on

How to structure methods and functions in a React component

Methods in components could be organized using comments. Common usecases can be broken down into the following comment headers.

  1. // STATES
  2. // ONMOUNT
  3. // WATCHERS
  4. // METHODS
  5. // COMPUTED

comment headers

Conclusion

  • The name of a variable or function should tell you what it is and how it is used.

  • Comments can lie. They can be wrong to begin with, or they can be originally accurate and then become outdated over time as the related code changes.

  • Comments can often be avoided by using clearly named variables and extracting sections of code into clearly named functions.

  • Comments that describe what a method does, what arguments it takes, and what it returns are often redundant at best and misleading at worst.

References

In Defense of Clean Code

Sentry mobile image

Improving mobile performance, from slow screens to app start time

Based on our experience working with thousands of mobile developer teams, we developed a mobile monitoring maturity curve.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay