You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the React Optimization section of the docs exists a suggestion to postpone dereferencing by using "getter" functions:
constMyComponent=({ person, car })=>(<><GenericNameDisplayergetName={()=>person.name}/><GenericNameDisplayergetName={()=>car.model}/><GenericNameDisplayergetName={()=>car.manufacturer.name}/></>)
This suggestion is unclear to me for two reasons:
I suppose the example is intentionally not wrapping MyComponent in observer to avoid dereferencing person.name (for example) and from triggering re-renders on MyComponent. How would this look like if we were to access person or car from a store inside MyComponent instead of receiving it from props?
Aren't we passing (unmemoized) new functions on every render of MyComponent which would mean GenericNameDisplay gets re-rendered every time MyComponent does?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In the React Optimization section of the docs exists a suggestion to postpone dereferencing by using "getter" functions:
This suggestion is unclear to me for two reasons:
MyComponent
inobserver
to avoid dereferencingperson.name
(for example) and from triggering re-renders onMyComponent
. How would this look like if we were to accessperson
orcar
from a store insideMyComponent
instead of receiving it from props?MyComponent
which would meanGenericNameDisplay
gets re-rendered every timeMyComponent
does?Beta Was this translation helpful? Give feedback.
All reactions