AboutBlogContact
Frontend EngineeringSeptember 5, 2017 2 min read 69Updated: May 3, 2026

ReasonML: OCaml Types Meet React Components (2017)

AunimedaAunimeda
📋 Table of Contents

ReasonML: OCaml for React Developers

It's 2017, and while TypeScript is winning the mainstream, a group at Facebook is pushing ReasonML. Reason isn't a new language; it's a new syntax and toolchain for OCaml. It gives us the safety of a 20-year-old type system with a syntax that looks like JavaScript.

Why Reason?

OCaml has features that TypeScript can only dream of: true pattern matching, sound type inference (you almost never need to write type annotations), and ultra-fast compilation.

ReasonReact: The Better React

ReasonReact isn't just a wrapper; it's a more principled way to write components.

/* Counter.re */
type state = {count: int};
type action = | Increment | Decrement;

let component = ReasonReact.reducerComponent("Counter");

let make = (_children) => {
  ...component,
  initialState: () => {count: 0},
  reducer: (action, state) =>
    switch (action) {
    | Increment => ReasonReact.Update({count: state.count + 1})
    | Decrement => ReasonReact.Update({count: state.count - 1})
    },
  render: (self) =>
    <div>
      <button onClick=(_event => self.send(Decrement))> (ReasonReact.stringToElement("-")) </button>
      <div> (ReasonReact.stringToElement(string_of_int(self.state.count))) </div>
      <button onClick=(_event => self.send(Increment))> (ReasonReact.stringToElement("+")) </button>
    </div>
};

BuckleScript Interop

Reason compiles to JS via BuckleScript. The interop is surprisingly clean. You can use any JS library by writing a "binding."

[@bs.val] external alert : string => unit = "alert";

let handleClick = () => alert("Hello from Reason!");

In 2017, ReasonML is the "advanced" choice for teams that want more safety than TypeScript can provide without the steep learning curve of pure OCaml or Haskell.


Aunimeda builds modern web frontends - from single-page applications to complex multi-locale sites.

Contact us to discuss your frontend project. See also: Web Development, Corporate Website Development

Read Also

Next.js 13/14: Server Actions and the New App Router (2023)aunimeda
Frontend Engineering

Next.js 13/14: Server Actions and the New App Router (2023)

React is coming full circle. In 2023, Next.js Server Actions are bringing back the simplicity of PHP and Ruby on Rails with modern React components.

React Server Components: Decoding the Wire Format (2023)aunimeda
Frontend Engineering

React Server Components: Decoding the Wire Format (2023)

RSC is finally stable in Next.js 13.4. But what's actually happening in that .rsc stream? Let's decode the secret language of the server-client bridge.

RxJS and Redux-Observable: Mastering Asynchronous Side Effects (2017)aunimeda
Frontend Engineering

RxJS and Redux-Observable: Mastering Asynchronous Side Effects (2017)

Is Redux Thunk or Saga not enough? In 2017, we're using RxJS and Redux-Observable to treat our actions as a stream of events.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Web Development

Get Consultation All articles