On This Page
Reactivity
This guide focuses primarily on reactivity in the context of components.
Signals - Semantic UI uses a signals based approach for reactivity. This works by tracking references to reactive variables and then running a flush which triggers those reactions after their values change. For more information see our dedicated section on reactivity.
Sources of Reactivity
Reactive Data
Reactivity occurs when a reactive value is modified inside of a reactive context. If you want a value to render reactively, you must have both a reactive value and a reactive context.
Reactive Data Sources
- State
- Settings
- ReactiveVar
Reactive Data Contexts
- Template Conditionals
- Template Loops
- Template Expressions
Reaction
created inside your component
Non-Reactive Data
If you want to use or set a variable without triggering reactivity either a value or context must be non-reactive.
Non-Reactive Data Sources
- DOM Elements or Properties
- Properties set on your component
$
or$$
DOM Query Collections
Non-Reactive Data Contexts
- Component Methods
- Lifecycle Callbacks
- Event & Keyboard Handlers
Avoiding Reactivity - You can access reactive values with
peek
to avoid reactivity, and useReaction.nonreactive
to control the reactivity of a function.For more information see controlling reactivity.
Component Reactivity
State Reactivity
Your component’s state
is the internal store of reactivity for your component. When your component is initialized each state
property will become a reactiveVar
and will trigger reactivity inside a Reaction
.
State will also trigger reactivity in your template.
Settings Reactivity
Settings are not reactive inside a reaction
because they are not instances of reactiveVar
.
However settings are reactive inside templates, and will trigger updates when their underlying value changes.
Template Reactivity
Reactive variables can be accessed from inside a template without calling its get
or value
helper.
Expressions, loops, and conditionals are reactive contexts by default. If items
in this example grows the results will update automatically.
Advanced Use
All lifecycle events and callbacks will return reactiveVar
and
reaction
. These can be used to create scoped reactions that will be tied to the component’s lifecycle, and automatically torn down when the component is destroyed.
Exposing Reactivity
You can expose a reactiveVar
on your component instance to allow other components to rely on it as a source of reactivity. This can be a useful way to share reactivity across related parts of your app.
Component
state
andsettings
are not accessible outside your component unless they are exposed on your component instance.
Reducing Reactivity
Template expressions are reactive by default but this might not always be ideal. Template reactivity can be removed by using the nonreactive
helper
Learn more about controlling reactivity in the dedicated subsection for controlling reactivity