Faster Props Update

Faster state updates work out-of-the-box. However, in case of props updates, we don't know if we can reuse a component or not. Similar to React, we introduced a new life cycle method that can guide the infrastructure to reuse a component:

// The default return value is YES
- (BOOL)shouldComponentUpdate:(id<CKRenderComponentProtocol>)component;

If this method returns NO, the component and its subtree will be reused. Similar to faster state updates, the reuse life cycle method will be called:

// This method is being called on the new component with the reused component.
- (void)didReuseComponent:(id<CKRenderComponentProtocol>)component

When this method will be called?

  • Props update
  • State update on a parent component (if component B has a parent A with a state update, it's the same as Props updates)

CKComponentContext and CKComponentMutableContext

TL;DR

Unless you expect your context value to be changed during component generations, you should always use CKComponentContext (instead of CKComponentMutableContext).

CKComponentMutableContext Issue

If one of the component's children reads a value from CKComponentMutableContext, a component cannot not be reused. The reason is that in case of a component reuse, the component might have an incorrect value from the context. Unfortunately, the existing context API doesn't allow us to compare values between component generations.

Faster Props Update

CKComponentContext as a solution

In order to mitigate this issue, we introduced CKComponentContext, which expect the value of the context to stay the same between component generations (such as QE values). CKComponentContext does support Faster Props Updates and will allow your component generation to be faster.