'Are difference between named arrow function and anonymous arrow function in JSX Props?
Example with ComponentA:
Case 1: with named arrow function callback:
const ComponentA = () => {
const handleClick = () => {... /* do somthing */};
return (
<div onClick={handleClick}>Hello world</div>
)
}
Case 2: with anonymous arrow function callback:
const ComponentA = () => {
return (
<div onClick={() => {/* Do sumthing here */}}>Hello world</div>
)
}
I knowed case 1 and case 2 make child rerender, but I dont know about effect to memory leak.
Are there issues related to memory leak when use anonymous arrow function vs named arrow function ?
Thank you very much!
Solution 1:[1]
Arrow functions are always anonymous. What you're referring to as the named arrow function is actually a function assignment
// function assignment, function itself is not named
const handleClick = () => {};
As far as the performance difference, there is no difference. Both will create a new reference on each rerender.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Haseeb Anwar |
