Reason programming language attributes

How to start React project in Reason:

Variants

Variants in Reason are data types and structures. It can be used to define sets of symbols and data structures.
type animal = Cat(string) | Dog(string);

Functions

Functions in Reason are declared with an arrow and a return expression.

1
2
3
4
5
let speak = (animal) =>
switch (animal) {
| Cat(name) => name ++ " says: meow"
| Dog(name) => name ++ " says: woof"
};

React

A React component can either be stateless or stateful. In ReasonReact, there are different ways of defining them:

  • Stateless components: defined as ReasonReact.statelessComponent("componentName")
  • Stateful components: defined as ReasonReact.reducerComponent("componentName")

let make = (~message, _children) => {
The first parameter has a symbol ~ indicating that it was passed into the App component as a props and the second parameter has _, this is a more explicit way of showing that the parameter isn’t used and ignored.