Search code examples
reactjsarrow-functions

fat arrow componentDidMount


I found in legacy code

componentDidMount = () => {
...
}

I know it is not valid, but it works. Now, I am curious what is the difference between this, and the right way

componentDidMount() {
...
}

Solution

  • Hi basically you can do it, but it's unnecessary and can also hurt performance. Because each time your function does an arrow operation, it has to create a new function object. So it's just an optimization choice.

    Good threads and articles: