Skip to content

Commit c217dd0

Browse files
committed
add state getter info
1 parent 27eb456 commit c217dd0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

guides/interactivity-api-getting-started.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ $additional_attributes = [
126126

127127
If you change the value of `isActive` in the context the `is-active` class will get added or removed from the div.
128128

129+
:::info
130+
The Interactivity API two different ways for keeping track of state. Context is used for local state. It is only available to the block itself and any child elements. The DOM is the source of truth here.
131+
132+
There also is `state` which is global and shared across all instances of the block and can be accessed by other blocks as well.
133+
134+
In this example we are using `context` because we only need the state to be available to the block itself.
135+
136+
State also has one more trick up it's sleve. Unlike context, state also allows you to define derrived state. This is state that is calculated based on other state or even context values. So you can for example access the `context` inside a `state` getter and return a value based on that.
137+
:::
138+
129139
### Lets make it interactive
130140

131141
Now that we have our context defined we can start to add some interactivity to our block. This is done by defining actions that can be triggered by the user.

0 commit comments

Comments
 (0)