简体   繁体   中英

When to use the static keyword before a method in a React class component

I'm use to writing methods in react like so:

class Someclass extends Component{
  ...
  someMethod () => ...
}

Latley I've seen a lot of code with static before the method name:

static someMethod() {...}
  1. What's the static for in the context of a JavaScript Class?
  2. And in the context of a React component?

Methods are defined on the class´s prototype, static methods are not, they are functions on the class itself. You can call a static method without creating the instance of the class.

More information on the subject here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM