We can declare methods of component class as arrow functions, like so:
class SomeComponent extends React.Component {
someMethod = () => { // <<----- This does not throw error
// some code
}
}
..that won't throw any error, but below does:
class SomeNormalClass {
someMethod = () => { // <<----- This throws error
// some code
}
}
It says unexpected =
after someMethod
. It works fine if I change my someMethod
back to normal function instead of declaring it as an arrow function as shown below. Why?
class SomeNormalClass {
function someMethod() { // <<----- This works fine
// some code
}
}