How to create js template literals in ReasonML/BS

interop

#1

Hi Folks. Does anyone know how to generate and populate a js template literal from Reason or Bs? For example:

let view state = 
   [%magic  `<div>${state.name}</div>` %]

I can use raw tags to create a template literal, but I don’t see any direct way to populate the variable fields.

 [%raw {| `<div>${state.name}</div>` |}]

Has anyone attempted this before? Any help is appreciated!


#2

Try it

    let f = fun%raw (state) => "`<div>${state.name}</div>`";

More info here https://bucklescript.github.io/docs/en/embed-raw-javascript.html


#3

Well, there it is :smile: . Thanks!


#4

You could use Quoted strings

let world = {js|世界|js}; /* Supports Unicode characters */
let helloWorld = {j|你好,$world|j}; /* Supports Unicode and interpolation variables */