Skip to content

v0.5.0 - createEffect

Compare
Choose a tag to compare
@ayushmanchhabra ayushmanchhabra released this 17 Jun 04:29
· 603 commits to main since this release
330e61c

The createEffect function is a way to manage side effects. It uses the MutationObserver API internally. The dependency array accepts a string of ids corresponding to their DOM element(s).

If the dependency array is empty, the callback runs only once (since the app is rendered only once).

createEffect(() => {
  console.log("Hello, World!");
}, [])

If the dependency array is not empty, the callback runs every time there is a change in a corresponding element or child of an element.

...

const [count, setCount] = createState(0);

createEffect(() => {
  console.log("Update value of count: ", count().value);
}, [count().key])

...

Full Changelog: v0.4.0...v0.5.0