S
S copied to clipboard
Local state inside effect / hooks
I have a question. It's a bad idea for S to create something like a local state for effects (hooks?)? For example
const $source = S.value(0);
const $target = S.value(0);
$.effect(() => {
const $throttler = S.localValue(0);
const throttler = S.sample($throttler);
const source = $source();
$throttler(throttler + 1);
if (throttler % 3 === 0) {
$target(source);
}
})
$source($source() + 1)
$source($source() + 1)
$source($source() + 1)
Yeah it is, just use let
You're free to create signals inside effects (or effects inside effects) and this can sometimes be useful. In this particular example though, like @yamiteru said, you can use a regular variable instead of a signal.