September 2022
Intermediate to advanced
410 pages
10h 7m
English
Our code is pretty simple so far, but it’s still missing a bit of functionality. We’re not yet changing the text of the button from “Hide” to “Show.” On a more structural level, we don’t have a place in the code that explicitly stores the state of the button. We have to infer the state from the presence or absence of the hidden class, which is not a terrible thing to have to do, but it’s often better to explicitly have the state of the system available.
We can do all of these things using another Stimulus concept: values. In Stimulus, values are a bit of syntactic sugar that allow us to use data attributes to store data that is specifically associated with a controller, and gives the controller some methods to manipulate that data ...