[REASONML] Using Javascript npm package from REASON
For example, we want to use moment.js inside our ReasonML code.
What we can do is create a module file:
//Moment.re type tt; external momentWithDate : Js.Date.t => tt = "moment" [@@bs.module]; external format : tt => string => string = "" [@@bs.send];
Using it inside component:
/* This is the basic component. */
let component = ReasonReact.statelessComponent "Page"; /* Your familiar handleClick from ReactJS. This mandatorily takes the payload,
then the `self` record, which contains state (none here), `handle`, `reduce`
and other utilities */
let handleClick _event _self => Js.log "clicked!"; let momentNow = Moment.momentWithDate(Js.Date.make()); /* `make` is the function that mandatorily takes `children` (if you want to use
`JSX). `message` is a named argument, which simulates ReactJS props. Usage: `<Page message="hello" />` Which desugars to `ReasonReact.element (Page.make message::"hello" [||])` */
let make ::message ::times _children => {
...component,
render: fun self =>
<div onClick=(self.handle handleClick)>
(ReasonReact.stringToElement message)
(ReasonReact.stringToElement times)
(ReasonReact.stringToElement (Moment.format momentNow "dddd"))
</div>
};
[REASONML] Using Javascript npm package from REASON的更多相关文章
- Angular Npm Package.Json文件详解
Angular7 Npm Package.Json文件详解 近期时间比较充裕,正好想了解下Angular Project相关内容.于是将Npm官网上关于Package.json的官方说明文档进行了 ...
- [WASM Rust] Create and Publish a NPM Package Containing Rust Generated WebAssembly using wasm-pack
wasm-pack is a tool that seeks to be a one-stop shop for building and working with Rust generated We ...
- Node.js NPM Package.json
章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json Nod ...
- [Node.js] Configuring npm package.json scripts
With a node package manager's (npm) package.json script property, you can preconfigure common tasks ...
- [NPM + React] Prepare a Custom React Hook to be Published as an npm Package
Before we publish our package, we want to make sure everything is set up correctly. We’ll cover vers ...
- npm & package.json & directories & files
npm & package.json & directories & files package.json https://docs.npmjs.com/files/packa ...
- npm package.json属性详解
概述 本文档是自己看官方文档的理解+翻译,内容是package.json配置里边的属性含义.package.json必须是一个严格的json文件,而不仅仅是js里边的一个对象.其中很多属性可以通过np ...
- npm package.json配置整理
通过npm init 创建 package.json文件 参数: name:项目名字 version: 版本号 description: 项目介绍 main: 项目的入口文件 scripts: npm ...
- 极简 Node.js 入门 - 1.4 NPM & package.json
极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...
随机推荐
- Unity 编辑器学习(二)之 全局光照(GI)
光影流年,花影阡陌.光与影交织的岁月教育我们,不会使用光照的程序员不是个好美术. 一.概述 点击 Window > Lighting > Settings 会弹出Lighting窗口,这个 ...
- 洛谷 P1542 包裹快递
P1542 包裹快递 题目描述 小K成功地破解了密文.但是乘车到X国的时候,发现钱包被偷了,于是无奈之下只好作快递员来攒足路费去Orz教主…… 一个快递公司要将n个包裹分别送到n个地方,并分配给邮递员 ...
- iOS 卖票中多线程分析;
注意:(主要一个加锁机制)
- zzulioj--1089--make pair(dfs+模拟)
1809: make pair Time Limit: 1 Sec Memory Limit: 128 MB Submit: 60 Solved: 44 SubmitStatusWeb Board ...
- Android 设置屏幕不待机
本文转载于:http://blog.csdn.net/yudajun/article/details/7748760 androidnullservice 目录(?)[+] 最近做项目时正好用到,进行 ...
- Mysql source导入.sql文件深坑!
刚刚接手一个项目,给老系统加功能.把数据库考出来一个.sql文件就170多M. 使用mysql命令行source 我的.sql文件. 导了一宿都没导完,然后发现里面的数据怎么是乱码呢.. 崩溃额,在排 ...
- COWRUN
USACO COWRUN 随机化搜索+双重递归调用 题面描述:给出8*N(<=14)组牌,每次按顺序选择8张,FJ可以选择前4张或者后4张,COW从FJ选出的牌中选择前两张或者后两张,然后COW ...
- K-近邻算法学习
# -- coding: utf-8 -- from numpy import * import operator def createDataSet(): group = array([[1.0,1 ...
- [ES2017] Iterate over properties of an object with ES2017 Object.entries()
The Object.entries() function is an addition to the ECMAscript scpec in Es2017. This allows us to it ...
- 从设计到实现,一步步教你实现Android-Universal-ImageLoader-辅助类
通过前面几篇博文.我们分析了 AUI 的缓存.工具类.显示与载入这几个方面的代码.今天呢,我们继续研究 AUI 的源代码,学习当中的核心辅助工具类. 希望大家能在里面学到东西哈. Download 要 ...