February 2019
Beginner to intermediate
180 pages
4h 4m
English
Although our example correctly shows the message when count reaches 10 for the first time, there is nothing preventing our ToggleMessage action from getting fired again within the UpdateCount case in the reducer. If a user gets to 10, then decrements and then increments, the message is toggled again. To ensure that UpdateCount only ever triggers the ToggleMessage action once, we can use an instance variable in state.
In ReactJS, every time something in state changes, the component gets re-rendered. In ReasonReact, instance variables never trigger a re-render, and can be correctly placed within a component's state.
Let's add an instance variable to keep track of whether the user has already seen the message:
type state ...
Read now
Unlock full access