Function directives

Simple one! How do I put “use memo” or “worklet” etc at the top of a function?

1 Like

Try @@directive

1 Like

Use @directive on the function definition (not the let binding):

let someFn =
  @directive("'use memo'")
  () => {
    Console.log("Hello")
  }

function someFn() {
  'use memo';
  console.log("Hello");
}
1 Like

Thanks, that’s only allowed at root file level though.

Thanks, this doesn’t work in ReScript 11.1.4 at least. Is there a minimum version for this?

Playground link

I think this is v12 only, which is in release candidate now.

2 Likes