[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 ...
随机推荐
- 守护、互斥锁、IPC和生产者消费者模型
守护进程 主进程创建守护进程 其一:守护进程会在主进程代码执行结束后就终止 其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic processes are ...
- div和css:行内元素和块元素的水平和垂直居中
行内元素: 水平居中:text-align:center ul水平居中:加 display:table; margin:0 auto; 此元素会作为块级表格来显示(类似 <table>), ...
- OpenGL 获取当前屏幕坐标对应的三维坐标
转自原文 OpenGL 获取当前屏幕坐标对应的三维坐标,使用很简单glu库中的一个函数 #include <GL/glut.h> #include <stdlib.h> #in ...
- [Python] Boolean Or "Mask" Index Arrays filter with numpy
NumPy Reference: Indexing Integer array indexing Boolean array indexing Note: The expression a < ...
- 百度地图SDK for Android【Demo兴趣点搜索】
百度地图SDK为开发人员提供了便捷的检索服务. 今天我将为大家介绍Poi检索相关的内容. 首先,我们要构建一个最主要的地图应用.详细介绍请參考:百度地图SDK for Android[ ...
- 不要小看了get 与set
不知道大家曾经是怎么使用实体中的get与set的.我先前是这样使用的. 先定义一个实体类.之后写与之相关的字段名称.最后匹配上与之相关的属性,控制字段的读写权限. 曾经使用方式 代码1 public ...
- Class C++
为了尽量降低全局变量的使用并提供用户自己定义类型的功能.C++语言提供了一种新的语言机制---类(class).并以类作为构造程序的基本单位 #include<iostream> usin ...
- 算法导论————KMP
[例题传送门:caioj1177] KMP模版:子串是否出现 [题意]有两个字符串SA和SB,SA是母串,SB是子串,问子串SB是否在母串SA中出现过.如果出现过输出第一次出现的起始位置和结束位置,否 ...
- 学习《TensorFlow实战Google深度学习框架 (第2版) 》中文PDF和代码
TensorFlow是谷歌2015年开源的主流深度学习框架,目前已得到广泛应用.<TensorFlow:实战Google深度学习框架(第2版)>为TensorFlow入门参考书,帮助快速. ...
- Django_模型操作