Function set_timeout_with_handle
pub fn set_timeout_with_handle(
cb: impl FnOnce() + 'static,
duration: Duration,
) -> Result<TimeoutHandle, JsValue>
Expand description
Executes the given function after the given duration of time has passed, returning a cancelable handle.
setTimeout()
.
§Note about Context
The callback is called outside of the reactive ownership tree. This means that it does not have access to context via use_context
. If you want to use context inside the callback, you should either call use_context
in the body of the component, and move the value into the callback, or access the current owner inside the component body using Owner::current
and reestablish it in the callback with Owner::with
.