Skip to content

Instantly share code, notes, and snippets.

@jdeisenberg
jdeisenberg / QueryString.re
Last active August 22, 2019 04:25
Parse a query string in ReasonML
/*
* Define a type that can be either a single string or a list of strings
*/
type queryItem =
| Single(string)
| Multiple(list(string));
/*
* Make a string “safe” by
@jaredly
jaredly / App.re
Last active January 1, 2021 17:34
ReasonReact Context API Example
module StringContext =
Context.MakePair({
type t = string;
let defaultValue = "Awesome";
});
let component = ReasonReact.statelessComponent("Tree");
let make = _children => {
import React from 'react'
export default function useDarkMode({
intervalTime = 300,
getIsDark = defaultGetIsDark,
} = {}) {
// Keep track of the current mode
const [isDark, setIsDark] = React.useState(() => getIsDark())
// Set up the checker
@chenglou
chenglou / code.re
Last active July 18, 2021 12:13
Recommended way to do HTTP requests in ReScript
// bindings can be isolated/upstreamed. I'm inlining it just for the example
type request;
type response;
[@bs.new] external makeXMLHttpRequest: unit => request = "XMLHttpRequest";
[@bs.send] external addEventListener: (request, string, unit => unit) => unit = "addEventListener";
[@bs.get] external response: request => response = "response";
[@bs.send] external open_: (request, string, string) => unit = "open";
[@bs.send] external send: request => unit = "send";
[@bs.send] external abort: request => unit = "abort";
// =========