mozilla-frontend-infra / discussions

4 stars 0 forks source link

Using `this` in each component method #3

Closed darkwing closed 7 years ago

darkwing commented 7 years ago

So I've been using getInitialProps to help manage state, but I get the usual Expected 'this' to be used by class method 'getInitialProps' class-methods-use-this error. Seems weird to have getInitialProps be a function outside of the class.

What do you guys do here?

eliperelman commented 7 years ago

In TaskCluster's neutrino web preset ESLint rules, we specifically shut off class-methods-use-this:

// Allow using class methods with static/non-instance functionality
// React lifecycle methods commonly do not use an instance context for anything
'class-methods-use-this': 'off',

Like you're seeing, React requires some lifecycle methods, which may not use the class's context, making ESLint cry. Maybe we should port the TaskCluster web preset to be our rpweb baseline preset.

purelogiq commented 7 years ago

I also have encountered this headache, and have valid cases for not using this in a class method.

eliperelman commented 7 years ago

This has been resolved in the new rpweb neutrino preset.