removeDuplicates in WithViewStore not working? #495
Replies: 3 comments 4 replies
-
Was just about to post this exact question but found this one instead, so here's a shameless bump! Even just returning Any help would be appreciated! |
Beta Was this translation helpful? Give feedback.
-
One way to tell what's causing re-rendering is to use...
Also, you can use
See this article for additional details and strategies: https://www.avanderlee.com/swiftui/debugging-swiftui-views/ |
Beta Was this translation helpful? Give feedback.
-
Ok I figured it out! 😅 Turns out @stephencelis was right; the problem was my very root view's ViewStore observing { $0 } which was causing a lot of extra re-renders, so pretty much all the child views where I was trying to narrow the ViewState and the removeDuplicates was getting ignored/bypassed. By reconsidering exactly what the root view needed to observe so as to avoid any unnecessary re-renders, the child views started behaving as I expected! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys...
Maybe someone can shed some light into an issue I'm running using SwiftUI and TCA.
I'm implementing removeDuplicates in a WithViewStore initializer in order to avoid re-rendering my view when state doesn't change (the view relies heavily on custom paths and shapes) but I can't seem to make it work. The view still re-renders even though state hasn't change. This ends up affecting the overall performance of my app.
Here's my WithViewStore initializer:
And here's how I implemented the isDuplicate function:
By using print() in my code I can see that the isDuplicate function is being called correctly before each render and even though it returns true (state hasn't changed) all views wrapped inside WithViewStore still re-render.
If I redo the entire view using standard SwiftUI code without TCA and using local state and conform the view to Equatable I can avoid re-renders all together as intended.
Can anyone help? What am I doing wrong here? :)
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions