February 2019
Beginner to intermediate
180 pages
4h 4m
English
The difference between ReasonReact instance variables and normal state variables is the use of ref. Previously, we saw that state.userHasSeenMessage is of type ref(bool) instead of bool. That makes state.userHasSeenMessage an instance variable.
Since ref is just syntactic sugar for a record type with a mutable field, let's first discuss mutable record fields.
To allow a record field to be mutable, prefix the field's name with mutable. Then, those fields can be updated in place using the = operator:
type ref('a) = { mutable contents: 'a};let foo = {contents: 5};Js.log(foo.contents); /* 5 */foo.contents = 6;Js.log(foo.contents); /* 6 */
However, the type declaration is already included in Reason's standard library, so ...
Read now
Unlock full access