October 2017
Intermediate to advanced
370 pages
8h 57m
English
We can set and update state properties with the AMP.setState() action. To set a property username, we could use the following:
AMP.setState({username: 'eadaoin'})
If the username property doesn't already exist, then it will be created and set to value eadaoin, and the state will be as follows:
{ username: 'eadaoin'}
Note that this is subtly different to the state when initialized with the amp-state element. When initialized with amp-state, the state will always be nested inside a property with name corresponding to the id of the amp-state element. In our earlier example, the id was user, and it resulted in this state:
{ user: { username: "ruadhan", address: { ... } }}
Thus, to update the username in the ...
Read now
Unlock full access