Call a static function into the class React ES6

前端 未结 2 501
终归单人心
终归单人心 2020-12-15 03:28

I have the following ReactJS class:

import React from \'react\'

export class Content extends React.Component {

  static getValue(key) {
    return key
  }
         


        
2条回答
  •  情话喂你
    2020-12-15 03:40

    A static method needs to be accessed on the class not an instance. So in your case, use:

    Content.getValue()

    However, a static method won't be able to access this -- I don't think you want the method to be static based on your code sample above.

    More: Static Members in ES6

提交回复
热议问题