Trait HigherOrderComponent

Source
pub trait HigherOrderComponent<T: Component> {
    type HOCProps: Props + Clone;

    // Required method
    fn transform_props(hoc_props: &Self::HOCProps) -> T::Props;

    // Provided methods
    fn enhance_component(
        component: &mut T,
        hoc_props: &Self::HOCProps,
    ) -> Result<(), ComponentError> { ... }
    fn on_wrapped_mount(
        component: &mut T,
        context: &MountContext,
        hoc_props: &Self::HOCProps,
    ) -> Result<(), ComponentError> { ... }
    fn on_wrapped_update(
        component: &mut T,
        changes: &StateChanges,
        hoc_props: &Self::HOCProps,
    ) -> Result<(), ComponentError> { ... }
    fn on_wrapped_unmount(
        component: &mut T,
        context: &UnmountContext,
        hoc_props: &Self::HOCProps,
    ) -> Result<(), ComponentError> { ... }
}
Expand description

Trait for defining higher-order component behavior

Required Associated Types§

Source

type HOCProps: Props + Clone

The props type for the HOC itself (should match T::Props)

Required Methods§

Source

fn transform_props(hoc_props: &Self::HOCProps) -> T::Props

Transform HOC props into wrapped component props

Provided Methods§

Source

fn enhance_component( component: &mut T, hoc_props: &Self::HOCProps, ) -> Result<(), ComponentError>

Optional: modify the wrapped component after creation

Source

fn on_wrapped_mount( component: &mut T, context: &MountContext, hoc_props: &Self::HOCProps, ) -> Result<(), ComponentError>

Optional: intercept lifecycle events

Source

fn on_wrapped_update( component: &mut T, changes: &StateChanges, hoc_props: &Self::HOCProps, ) -> Result<(), ComponentError>

Optional: intercept state changes

Source

fn on_wrapped_unmount( component: &mut T, context: &UnmountContext, hoc_props: &Self::HOCProps, ) -> Result<(), ComponentError>

Optional: intercept unmount

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§