!cIzXunmotJOkxckVaw:matrix.org

Random

726 Members
3 Servers

Load older messages


SenderMessageTime
17 Sep 2023
@_discord_326088262118670337:t2bot.iokirillsemyonkin you dont like sending callbacks down the tree, which i think you mean sending a prop parent -> child -> child -> child - this is called prop drilling, and you may solve it just using built-in ContextProvider

pseudo example code that may not have all derives needed:
#[derive(Clone, PartialEq)]
pub struct YourContext {
    callback: Callback<SomeThing, SomeThing>;
}

impl YourContext {
    pub fn callback(&self, thing: SomeThing) -> SomeThing {
        self.callback.emit(thing)
    }
}

#[function_component]
pub fn Parent(...children...) -> Html {
    let callback = ...;
    let context = YourContext { callback };
    html! {
        <ContextProvider<YourContext> { context }>
            { children.clone() }
        </ContextProvider>
    }
}

#[function_component]
pub fn Child() -> Html {
    let context = use_context::<YourContext>().unwrap();
    ...context.callback(...)...
}

#[function_component]
pub fn Main() -> Html {
    html! {
        <Parent>
            <Child />
        </Parent>
    }
}
10:59:31
@_discord_326088262118670337:t2bot.iokirillsemyonkin * you dont like sending callbacks down the tree, which i think you mean sending a prop parent -> child -> child -> child - this is called prop drilling, and you may solve it just using built-in ContextProvider

pseudo example code that may not have all derives needed:
#[derive(Clone, PartialEq)]
pub struct YourContext {
    callback: Callback<SomeThing, SomeThing>;
}

impl YourContext {
    pub fn callback(&self, thing: SomeThing) -> SomeThing {
        self.callback.emit(thing)
    }
}

#[function_component]
pub fn Parent(...children...) -> Html {
    let callback = ...;
    let context = YourContext { callback };
    html! {
        <ContextProvider<YourContext> { context }>
            { children.clone() }
        </ContextProvider<YourContext>>
    }
}

#[function_component]
pub fn Child() -> Html {
    let context = use_context::<YourContext>().unwrap();
    ...context.callback(...)...
}

#[function_component]
pub fn Main() -> Html {
    html! {
        <Parent>
            <Child />
        </Parent>
    }
}
10:59:45
@_discord_326088262118670337:t2bot.iokirillsemyonkin https://yew.rs/docs/next/concepts/contexts 11:00:06
@_discord_326088262118670337:t2bot.iokirillsemyonkin two things here:
- callback is not prop-drilled, because we use contexts
- child does not know that theres an actual Callback, we hid it from them by using impl YourContext
11:05:14
@_discord_326088262118670337:t2bot.iokirillsemyonkin also, UseStateSender and UseReducerDispatch are pretty much Callbacks and you may use them as a shortcut 11:09:34
@_discord_326088262118670337:t2bot.iokirillsemyonkin * also, UseStateSetter and UseReducerDispatch are pretty much Callbacks and you may use them as a shortcut 11:09:38
@_discord_354616368064102401:t2bot.iokraem_ thanks. i'll have to read up on contexts. 11:56:16
@_discord_139653598425382912:t2bot.ioholg_#0 changed their display name from holg to holg_#0.12:05:02
18 Sep 2023
@ryanpaaaj:matrix.org@ryanpaaaj:matrix.org joined the room.05:16:46
@ryanpaaaj:matrix.org@ryanpaaaj:matrix.org left the room.05:51:33
@_discord_1056191399588012082:t2bot.ioatoktoto joined the room.08:41:31
@_discord_292724790744317953:t2bot.ioxkrebs_ changed their display name from xkrebs_ to xkrebs_#0.11:31:53
@_discord_292724790744317953:t2bot.ioxkrebs_ changed their display name from xkrebs_#0 to xkrebs_.11:31:54
@nimilv:matrix.orgMinimaul πŸ‡ΊπŸ‡ΈπŸ³οΈβ€πŸŒˆ changed their profile picture.12:29:02
@nimilv:matrix.orgMinimaul πŸ‡ΊπŸ‡ΈπŸ³οΈβ€πŸŒˆ changed their profile picture.12:33:51
19 Sep 2023
@_discord_435285100435865603:t2bot.iopissmilk#0 changed their profile picture.04:53:34
@_discord_472777681126162433:t2bot.iotiresias___ joined the room.14:16:19
@_discord_1124594163233591386:t2bot.iojias7dp8b71#0 changed their display name from jias7dp8b71 to jias7dp8b71#0.15:55:19
@tomidomino:cutefunny.art@tomidomino:cutefunny.art joined the room.19:54:35
@tomidomino:cutefunny.art@tomidomino:cutefunny.art left the room.20:01:09
22 Sep 2023
@_discord_593226209354317845:t2bot.iosergioribera#0 changed their display name from Sergio Ribera to sergioribera#0.20:30:39
@nimilv:matrix.orgMinimaul πŸ‡ΊπŸ‡ΈπŸ³οΈβ€πŸŒˆ changed their profile picture.21:24:19
@nimilv:matrix.orgMinimaul πŸ‡ΊπŸ‡ΈπŸ³οΈβ€πŸŒˆ changed their profile picture.21:26:16
23 Sep 2023
@dkmon23:matrix.org@dkmon23:matrix.org left the room.10:19:29
@_discord_203302899277627392:t2bot.ioSimon changed their display name from siku2#0001 to siku2#0.18:04:56
@_discord_203302899277627392:t2bot.ioSimon changed their display name from siku2#0 to Simon.18:04:59
@_discord_1108040720033521767:t2bot.io.xiqq joined the room.21:58:57
@_discord_802748079404875796:t2bot.io0xalcibiades joined the room.23:11:51
24 Sep 2023
@_discord_775145661103603735:t2bot.io.christopherhunt changed their display name from Christopher Hunt#2382 to .christopherhunt#0.04:16:49
@_discord_775145661103603735:t2bot.io.christopherhunt changed their display name from .christopherhunt#0 to .christopherhunt.04:16:49

There are no newer messages yet.


Back to Room ListRoom Version: 6