provide_context

Function provide_context 

Source
pub fn provide_context<T>(value: T)
where T: Clone + 'static,
👎Deprecated since 0.2.0: Use Context::provide instead; this will be removed in a future release
Expand description

Sets a context value to be stored in the current scope.

The stored context value can be retrieved by the current scope and any of its descendants using use_context. Child scopes can provide their own values of the same type, which will shadow the parent’s value for that subtree.

Context values are automatically cleaned up when the scope is disposed.

§Example

In a parent component:

provide_context(42);
provide_context(String::from("Hello world"));

And so in a child component you can retrieve each context data by specifying the type:

let foo: Option<i32> = use_context();
let bar: Option<String> = use_context();