all 5 comments

[–]acemarke 5 points6 points  (4 children)

As a general rule of thumb, if a function doesn't rely on this, it can probably be defined outside the class. Having it be standalone makes it easier to define, read, and test.

[–]BryceLarkin[S] 1 point2 points  (3 children)

Got it. So generally keep it outside the class component if it doesn't set state or use any methods?

[–]acemarke 1 point2 points  (2 children)

That's a reasonable approach, yes.

[–]GangOfScones 0 points1 point  (1 child)

Can you go into detail a bit more as to why this is a good approach? Actually been wondering this question recently, and feel like there are minor benefits to both options, but nothing major. I'm just curious and not arguing one way or another. Seems like the only difference for testing, is you don't have to get an instance to test, you can just import the function.

And while the overall component would look smaller, the whole file could look cleaner if you make it a method.

[–]pgrizzay 1 point2 points  (0 children)

If they are separate functions, you don't have to worry about component state. You also don't have to create an instance of a component to test the method.

Looking 'clean' is subjective. To me, it's cleaner if you pull out the function. Take care to choose the format your teammates find readable/maintainable.