Skip to Main Content
ReasonML Quick Start Guide
book

ReasonML Quick Start Guide

by Raphael Rafatpanah, Bruno Joseph D'mello
February 2019
Beginner to intermediate content levelBeginner to intermediate
180 pages
4h 4m
English
Packt Publishing
Content preview from ReasonML Quick Start Guide

Refactoring

Let's imagine we now need our stateful component to display a message that congratulates the user when they get to a count of 10, and once the message is displayed, the user can close the message by clicking a close button. Thanks to our helpful compiler, we can follow these steps:

  1. Update the shape of state
  2. Update the available actions
  3. Step through the compiler errors
  4. Update the render function

The compiler messages will remind us to update the component's initial state and reducer. Since we now need to also keep track of whether or not to display a message, let's change the shape of state to this:

type state = {  count: int,  showMessage: bool};

For our actions, let's combine Increment and Decrement into one constructor that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
Expert F# 4.0, Fourth Edition

Expert F# 4.0, Fourth Edition

Don Syme, Adam Granicz, Antonio Cisternino
Learn Type-Driven Development

Learn Type-Driven Development

Soumya Mukherjee, Yawar Amin, Kamon Ayeva

Publisher Resources

ISBN: 9781789340785Supplemental Content