$inspect rune is roughly equivalent to console.log, with the exception that it will re-run whenever its argument changes. $inspect tracks reactive state deeply, meaning that updating something inside an object or array using fine-grained reactivity will cause it to re-fire.
$inspect only works during development. In a production build it becomes a noop.Signature
One or more values to inspect. Can be any reactive state.
Basic usage
$inspect(…).with
$inspect returns a property with, which you can invoke with a callback, which will then be invoked instead of console.log. The first argument to the callback is either "init" or "update"; subsequent arguments are the values passed to $inspect:
A callback function to invoke instead of
console.log. The first argument indicates whether this is the initial run or an update.$inspect.trace(…)
An optional label for the trace output.
Use cases
$inspect is particularly useful for:
- Debugging reactive state changes
- Understanding when and why effects re-run
- Tracking down unexpected reactivity
- Learning how Svelte’s reactivity system works
- Basic logging
- Custom handler
- Trace effects