reactively icon indicating copy to clipboard operation
reactively copied to clipboard

Is there a replacement for "effect"?

Open cwayfinder opened this issue 1 year ago • 2 comments

How to run a function whenever one or more dependency values change?

For example, we have the following code

// declare some reactive variables.
const counter = reactive(0);
const isEven = reactive(() => (counter.value & 1) == 0);
const render = reactive(() => {
  document.body.textContent = isEven.value ? "even" : "odd";
});

How to run render() automatically whenever the counter changes?

cwayfinder avatar May 25 '23 06:05 cwayfinder

One way to do that is:

autoStabilize();

// declare some reactive variables.
const counter = reactive(0);
const isEven = reactive(() => (counter.value & 1) == 0);
const render = reactive(() => {
  document.body.textContent = isEven.value ? "even" : "odd";
}, {effect: true});

milomg avatar May 25 '23 17:05 milomg

What is autoStabilize() and what is {effect:true} ?

alijaya avatar Sep 24 '23 19:09 alijaya