Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 792 Bytes

File metadata and controls

41 lines (30 loc) · 792 Bytes
title Core Effect
id core-effect

Effect Documentation

The Effect class runs side effects when dependencies change, similar to useEffect in React.

import { Effect } from '@tanstack/store'

const logEffect = new Effect({
  deps: [counterStore],
  fn: () => console.log('Counter changed:', counterStore.state),
  eager: true // Run immediately on creation
})

Effect Options

EffectOptions

Configuration for creating effects.

interface EffectOptions {
  deps: ReadonlyArray<Derived<any> | Store<any>> // Dependencies to watch
  fn: () => void // Effect function to run
  eager?: boolean // Whether to run immediately (default: false)
}

Effect Methods

mount()

Activates the effect

effect.mount()