Hi peeps Still trying to integrate a few things to evaluate a potential move to rescript
One of the last two blocking things (the other one is state management but I’ve seen a couple of examples lying around) is the ability to load WASM modules into the react application.
In Nextjs+TS you would do something like this:
onClick: (function () {
import('wasm').then(wasm => wasm.greet())
}),
or
onClick: (async function () {
const wasm = await import('wasm')
wasm.greet()
}),
I manually wrote this inside my compiled .bs.js
and both versions work just as expected (wasm package is compiled by wasm-pack which handles the loading of the .wasm
itself)
What I’m struggling on is trying to write a Wasm.res
binding so that in my component I can just write
let handleClick = () => {
Wasm.greet()
}
If I write the following:
@module("../pkg")
external greet: unit => unit = "greet"
it compiles to
import * as Pkg from "../pkg";
function greet(prim) {
Pkg.greet();
}
export {
greet ,
}
which fails with TypeError: Method Promise.prototype.then called on incompatible receiver #<Promise>
I could maybe add a .js
to wrap this in, but ideally I’d like to minimise the amount of .js commited to the repo (I am already not a massive fan of having to wrap the compiled .bs.js to support the nextjs 13 file system pages.
I added a sample repo here GitHub - davodesign84/rescript-next please note you might need to replace your node path in /use-client-mod.cjs
Ideas? Any help would be super appreciated