June 2021
Intermediate to advanced
398 pages
9h 35m
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 better to explicitly have the state of the controller available.
We can do all of these things using another Stimulus concept: values. In Stimulus, values are a bit of syntactic sugar that allows 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 ...