March 2019
Intermediate to advanced
208 pages
5h 11m
English
Let’s use this new and improved shirt order program as the base for our final example in this chapter. We’ll store the state of the page in the browser’s local storage[48] in JSON format.
We’ll need to include @glennsl/bs-json in our bsconfig.json and install it via npm install --save @glennsl/bs-json, as we did:
| | "bs-dependencies": [ |
| | "reason-react", |
| | "@glennsl/bs-json" |
| | ], |
We need to add code to convert to and from JSON. First, let’s look at the Order type in file Shirt.re. The new entries here are the encodeJson and decodeJson functions:
| | module E = Json.Encode; |
| | module D = Json.Decode; |
| | |
| | module Order = { |
| | type t = { |
| | orderNumber |
Read now
Unlock full access