February 2019
Beginner to intermediate
180 pages
4h 4m
English
Let's break this down. At the top of the file, we see two type declarations, one for state and one for actions. The names state and action are a convention, but you can use any name you like:
type state = int;type action = | Increment | Decrement;
Just as in Redux, events trigger actions that are sent to a reducer that then updates state. Next, the button's click event triggers a Decrement action that gets sent to the component's reducer via self.send. Remember, the render function is provided self as its argument:
<button onClick={_event => self.send(Increment)}> {ReasonReact.string("+")}</button>
The state type declaration defines the shape of our state. In this case, our state is just an integer that holds the ...
Read now
Unlock full access