1

I do write code using both of these, but I want to have clarity on is there any difference between these two and if yes which one is the best one to use. ( which is the best practice and why? ) or is there no difference between these?

does use of Arrow functions have a performance impact, when used in a loop?

When we are passing an arrow function handler down to child components ( which is created in a loop ), does this impact the performance by anyway?

Can i by default stick to arrow function?

Arrow function:

renderPage = () => {
        this.props.pdfData.getPage(this.props.pdfPageNumber).then(
            this.handlePages();
        );
    }

Normal function with a bind:

constructor(){
 super();
 this.groupChange = this.groupChange.bind(this); 
}

groupChange = (selectedOption: any) => {
        this.setState({ selectedGroup: selectedOption });
        if (selectedOption) {
            console.log(`Selected: ${selectedOption.label}`);
        }
    }
Praveen Rao Chavan.G
  • 2,772
  • 3
  • 22
  • 33
  • Check [this](https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1). – AndrewL64 Jan 07 '19 at 06:34
  • If you want a function to have its own scope, you use the function keyword, and you can change the scope with `bind()`. But if your function needs to retain the scope from where it was called you use an arrow function. In either case, you shouldn’t need `var self = this` – Kokodoko Jan 07 '19 at 06:36

0 Answers0