Govur University Logo
--> --> --> -->
...

Imagine you have a special child screen part that only updates when its gifts change. If you give this child part a `doSomething` gift that is a function, and the parent screen part rebuilds, what special tool should the parent use to make sure the `doSomething` gift looks the same to the child if it hasn't truly changed, so the child doesn't update for no reason?



The special child screen part, which only updates when its "gifts" (properties) change, relies on comparing the current gifts to the previous gifts. When a function like `doSomething` is passed as a gift, the child typically checks if the function's *reference* has changed. In JavaScript, if a parent screen part rebuilds and defines a function directly within its render logic, even if the function's code is identical, a *new function object* is created in memory each time. This new function object has a different memory address, meaning its reference is different from the one passed in the previous render. Consequently, the child's comparison mechanism will see a changed gi....

Log in to view the answer



Redundant Elements