@@ -727,6 +727,28 @@ With function builders, you can even create your own DSLs. And this year in WWDC
727
727
Apple released more features based on function builders, like **WidgetKit ** and
728
728
SwiftUI **App Structure **.
729
729
730
+ How SwiftUI determine when to update a view?
731
+ --------------------------------------------
732
+ All views in SwiftUI are like **PureComponent ** in React by default. That means,
733
+ all the member variables (props) will be used to evaluate the equality, of course
734
+ it's shallow comparison.
735
+
736
+ What if you want to customize the update strategy? If you take a look at the
737
+ declaration of ``View `` protocol, you will notice this subtle thing:
738
+
739
+ .. code-block :: swift
740
+
741
+ extension View where Self : Equatable {
742
+
743
+ /// Prevents the view from updating its child view when its new value is the
744
+ /// same as its old value.
745
+ @inlinable public func equatable () -> EquatableView<Self >
746
+ }
747
+
748
+ SwiftUI provides an ``EquatableView `` to let you achieve that. All you need to do
749
+ is make your view type conform ``Equatable `` and implement the ``== `` function.
750
+ Then wrap it into ``EquatableView `` at the call-site.
751
+
730
752
.. References:
731
753
732
754
.. _`Thinking in React Hooks` : https://wattenberger.com/blog/react-hooks
0 commit comments