Syntax Lookup

Enter some language construct you want to know more about.

@@directive / @directive

These decorators emit JavaScript directives at file or function scope.

@@directive takes a string literal payload and emits it at the very top of the generated JavaScript file, before any imports.

This is useful for directives such as 'use client' in React Server Components.

Available since ReScript 10.1.4.

File-Level Example

ReScriptJS Output
@@directive("'use client'")

Since ReScript 12, @directive can also annotate a function expression. The directive is emitted at the start of the generated function:

ReScriptJS Output
let serverAction = @directive("'use server'") async (~name) => {
  "Hello " + name
}

Place the attribute after the binding's = and directly before the function. Function directives work with synchronous and asynchronous functions and with multiple or labeled parameters.

References