Understanding context selector performance impact
Hi! I'm debugging some performance issues and I'd like to understand why A performs worse than B?
For the record:
- "A" causes a lot of rerenders
- I created my router with
defaultStructuralSharing: true
(because I thought that would cover this exact case)
Is that because the shape of the object changes all the time (maybe because of functions returned by queryOptions
)? Thanks for your help
Please ping me!2 Replies
foreign-sapphire•3mo ago
I think your guess about "because of functions" might be right on the money. Maybe you could have a combination of both like below. The selector is only useful if stuff is likely to change a lot anyway. For a
useSearch
it makes a lot of sense. For a useRouteContext
, maybe it's overkill, and your "B" solution is actually the best way to do this.
Idk if that's much better in terms of ergonomics.inland-turquoiseOP•3mo ago
Thanks for confirming!