States
suggest change# States are read using the `state` method, and updated using `mutate`.
# When states change they cause a re-render of all dependent DOM elements.
class StateExample < Hyperloop::Component
state count: 0 # by default states are initialized to nil
render do
DIV do
SPAN { "Hello There" }
A { "Click Me" }.on(:click) { mutate.count(state.count + 1) }
DIV do
"You have clicked me #{state.count} #{'time'.pluralize(state.count)}"
end unless state.count == 0
end
end
end
Note that states can be shared between components using Hyperloop::Stores
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents