Expected 'this' to be used by class method

getUrlParams = queryString => { ... }

This is a ESlint rule, see class-methods-use-this.

You could extract the method getUrlParams and put it into a helper, or to make it static.

What could you also do is to move the this.props.location.search inside the method, therefore calling the this.getUrlParams() method without parameter, as it seems you are using it only once.

Therefore, this could look like:

getUrlParams() {
    const queryString = this.props.location.search;
    ...
    return params;
  }

A last option would be to disable this ESlint rule.


you should bind the function to this as the ESLint error says "Expected 'this' to be used by class method 'getUrlParams'

getUrlParams = (queryString) => { .... }

as you are not using getUrlParams during render (like onClick()) so the above technique is good which we can call it "usage of arrow function in class property".

there are other ways of binding too:

  • binding in constructor this.getUrlParams=this.getUrlParams.bind(this)
  • arrow function in render e.g.onClick={()=>this.getUrlParams()} assumed that function does not have params.
  • and React.createClass which with ES6 does not make sense :)