edifice.Component.set_key

Component.set_key(key)[source]

Sets the key of the component.

The key is used by the re-rendering logic to match a new list of components with an existing list of components. The algorithm will assume that components with the same key are logically the same. If the key is not provided, the list index will be used as the key; however, providing the key may provide more accurate results, leading to efficiency gains.

Example:

# inside a render call
return edifice.View()(
    edifice.Label("Hello").set_key("en"),
    edifice.Label("Bonjour").set_key("fr"),
    edifice.Label("Hola").set_key("es"),
)
Parameters

key (str) – the key to label the component with

Returns

The component itself.