case 1: file scope global function
// test.tsx
const someFunction = (text) => {
console.log(text)
}
class SomeComponent extends React.Component {
constructor(props){
super(props)
someFunction("Hello World!")
}
}
case 2: class method
// test2.tsx
class SomeComponent extends React.Component {
constructor(props){
super(props)
this.someFunction("Hello World!")
}
someFunction(text){
console.log(text)
}
}
in functional component, functions are recreated every render so you optimize it using useCallback but as far as I know, this is not the case for class component's methods.
Is there any difference in 2 approaches except that someFunction in case 1 can't access this?