| title | Core Effect |
|---|---|
| id | core-effect |
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
})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)
}Activates the effect
effect.mount()