February 2019
Beginner to intermediate
180 pages
4h 4m
English
Let's go off on a quick tangent to explore [@bs.variadic] a bit further. Let's assume you'd like to bind to Math.max(), which can take one or more arguments:
/* JavaScript */Math.max(1, 2);Math.max(1, 2, 3, 4);
This is a perfect case for [@bs.variadic]. We use an array on the Reason side to hold the arguments, and the array will be expanded to match the above syntax in JavaScript.
/* Reason */[@bs.scope "Math"][@bs.val][@bs.variadic] external max: array('a) => unit = "";max([|1, 2|]);max([|1, 2, 3, 4|]);
Okay, we're back to the styled-components example. We can use the <Title /> component as follows:
/* Home.re */let component = ReasonReact.statelessComponent("Home");let make = _children => { ...component, render: _self ...Read now
Unlock full access