!LtIECwsjkkjinzHTTB:matrix.org

Support/Help

942 Members
6 Servers

Load older messages


SenderMessageTime
27 Aug 2024
@imbev:matrix.org@imbev:matrix.org left the room.19:18:00
30 Aug 2024
@masterphp:matrix.org@masterphp:matrix.org joined the room.17:15:21
@masterphp:matrix.org@masterphp:matrix.org left the room.17:15:51
24 Jan 2022
@weeb69:matrix.orgweeb69 set the history visibility to "world_readable".16:10:04
@weeb69:matrix.orgweeb69 set the room name to "Support/Help".16:10:05
@weeb69:matrix.orgweeb69 invited @_discord_bot:t2bot.ioDiscord Bridge.16:10:22
@_discord_bot:t2bot.ioDiscord Bridge joined the room.16:10:24
@weeb69:matrix.orgweeb69!discord bridge 701068342760570933 70344930649702404916:10:41
@_discord_bot:t2bot.ioDiscord BridgeI'm asking permission from the guild administrators to make this bridge.16:10:42
@_discord_bot:t2bot.ioDiscord Bridge

I have bridged this room to your channel

16:10:49
@_discord_141600911725166593:t2bot.ioBrunkel#2646 joined the room.16:59:42
@_discord_141600911725166593:t2bot.ioBrunkel#2646Redacted or Malformed Event16:59:42
@_discord_141600911725166593:t2bot.ioBrunkel#2646 How can I use the gloo::timers::callback::Interval to increment my timer state each second? I'm confused about how I need to use the closures..

The code:
let timer = use_state(|| 0);
let mut interval: Interval;
fn start_timer() {
    interval = Interval::new(1_000, {
        let timer = timer.clone();
        move || {
          timer.set(*timer + 1);
        }
    });
}

Error msg: use the '|| { ... }' closure form instead
17:06:40
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 joined the room.17:10:11
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 is this in astruct component or function component? 17:10:11
@_discord_141600911725166593:t2bot.ioBrunkel#2646 function component 17:10:22
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396
let timer = use_state(|| 0);
use_effect_with_deps(move |_|{
    let interval = Interval::new(1_000, {
        let timer = timer.clone();
        move || { timer.set(*timer + 1); }
    });
},());
17:10:28
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 but be carefull as you timer inside the callback can desync 17:10:41
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 yeah actaully nvm this is really bad snippet 17:10:59
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 let me fix this 17:11:05
@_discord_141600911725166593:t2bot.ioBrunkel#2646 haha ok 17:11:14
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396
let timer = use_state(|| 0);
use_effect_with_deps(move |_| {
    let timer = timer.clone();
    let interval = Interval::new(1_000, move || { timer.set(*timer + 1); });
    move || drop(interval)
}, timer);
17:12:45
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 we need to recreate the closure every time timer updates 17:13:08
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 because other vise *timer will result in an old value 17:13:23
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 if dislike recreating timers 17:13:46
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 you can use a reducer instead of state 17:13:53
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 then yu would just send a some kinf of action like Action::Increment 17:14:14
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 and your use_effect_with_deps dependiecies could just be () 17:14:48
@_discord_141600911725166593:t2bot.ioBrunkel#2646 Ah makes sense. I'll use the reducer method. Thanks for the quick response 🙂 17:19:14
@_discord_278291088060710932:t2bot.iokrytain joined the room.20:35:23

Show newer messages


Back to Room ListRoom Version: 6