sycamore::reactive

Function provide_context_in_new_scope

pub fn provide_context_in_new_scope<T, U>(value: T, f: impl FnOnce() -> U) -> U
where T: 'static,
Expand description

Provide a context value in a new scope.

Since this creates a new scope, this function should never panic. If the context value already exists in the outer scope, it will be shadowed by the new value in the inner scope only. Outside of the new scope, the old context value will still be accessible.

ยงExample

provide_context(123);
assert_eq!(use_context::<i32>(), 123);

provide_context_in_new_scope(456, || {
    assert_eq!(use_context::<i32>(), 456);
});

assert_eq!(use_context::<i32>(), 123);