Struct dioxus_core::context::Context [−][src]
Components in Dioxus use the “Context” object to interact with their lifecycle. This lets components schedule updates, integrate hooks, and expose their context via the context api.
Properties passed down from the parent component are also directly accessible via the exposed “props” field.
#[derive(Properties)] struct Props { name: String } fn example(ctx: &Context<Props>) -> VNode { html! { <div> "Hello, {ctx.props.name}" </div> } }
Fields
idx: AtomicUsize_p: PhantomData<&'src ()>Implementations
impl<'a> Context<'a>[src]
pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>(
&'scope self,
initializer: impl FnOnce() -> InternalHookState,
runner: impl FnOnce(&'a mut InternalHookState) -> Output,
_cleanup: impl FnOnce(InternalHookState)
) -> Output[src]
&'scope self,
initializer: impl FnOnce() -> InternalHookState,
runner: impl FnOnce(&'a mut InternalHookState) -> Output,
_cleanup: impl FnOnce(InternalHookState)
) -> Output
TODO: @jon, rework this so we dont have to use unsafe to make hooks and then return them use_hook provides a way to store data between renders for functional components. todo @jon: ensure the hook arena is stable with pin or is stable by default
impl<'a> Context<'a>[src]
pub fn use_context<I, O>(&'a self, _narrow: impl Fn(&I) -> &O) -> RemoteState<O>[src]
impl<'a> Context<'a>[src]
pub fn children(&self) -> Vec<VNode<'_>>[src]
Access the children elements passed into the component
pub fn schedule_update(&self) -> impl Fn()[src]
Create a subscription that schedules a future render for the reference component
pub fn view(
self,
lazy_nodes: impl FnOnce(&'a Bump) -> VNode<'a> + 'a
) -> DomTree[src]
self,
lazy_nodes: impl FnOnce(&'a Bump) -> VNode<'a> + 'a
) -> DomTree
Take a lazy VNode structure and actually build it with the context of the VDom’s efficient VNode allocator.
This function consumes the context and absorb the lifetime, so these VNodes must be returned.
Example
fn Component(ctx: Context<Props>) -> VNode { // Lazy assemble the VNode tree let lazy_tree = html! {<div>"Hello World"</div>}; // Actually build the tree and allocate it ctx.view(lazy_tree) }
pub fn callback(&self, _f: impl Fn(()) + 'a)[src]
pub fn suspend(
&self,
_fut: impl Future<Output = impl FnOnce(&'a Bump) -> VNode<'a>>
) -> VNode<'a>[src]
&self,
_fut: impl Future<Output = impl FnOnce(&'a Bump) -> VNode<'a>>
) -> VNode<'a>
Create a suspended component from a future.
When the future completes, the component will be renderered
Auto Trait Implementations
impl<'src> !RefUnwindSafe for Context<'src>
impl<'src> !Send for Context<'src>
impl<'src> !Sync for Context<'src>
impl<'src> Unpin for Context<'src>
impl<'src> !UnwindSafe for Context<'src>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Erased for T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,