Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local state inside effect / hooks #42

Open
AStaroverov opened this issue Feb 15, 2021 · 2 comments
Open

Local state inside effect / hooks #42

AStaroverov opened this issue Feb 15, 2021 · 2 comments

Comments

@AStaroverov
Copy link

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)
@yamiteru
Copy link

Yeah it is, just use let

@nonphoto
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants