remember

Function remember 

Source
pub fn remember<F, T>(init: F) -> State<T>
where F: FnOnce() -> T, T: Send + Sync + 'static,
Expand description

Remember a value across recomposition (build) passes.

This function allows a component to “remember” state across recomposition (build) passes. The init closure is executed only once — when the component first runs. On subsequent updates, the stored value is returned and init is not called.

§Interior mutability

This function returns a State<T> handle that internally uses an Arc<RwLock<T>>. Use with, with_mut, get, or set to read or update the value without handling synchronization primitives directly.

§Comparison with remember_with_key

remember identifies stored state based on the component’s call order and control-flow path. It associates state by position within a component, but this does not work reliably for dynamically generated state inside loops. For state that is allocated dynamically in loops, consider using remember_with_key to explicitly provide a unique key.

§Panics

This function must be called during a component’s build/render phase. Calling it during the measure or input handling phases will panic.