Skip to content

@directive and @@directive improvements #8301

@CarlOlson

Description

@CarlOlson

Directives are a part of React and used by the React compiler. Frameworks like NextJs have started to rely on these heavily. ReScript should improve its support in order to take advantages of these features.

Suggested Changes:

  1. Always output value given to @@directive as a string. Example: @@directive("use client"), not @@directive("'use client'")

    Currently @@directive can generate invalid JS:

    @@directive("use client")
    // output
    use client
    
    // should be
    "use client"

    Directives are always strings, so we shouldn't need to add internal quotes.

  2. Support @directive for react components and functions

    @rescript.component @directive("use client")
    let make = () => {
      <div />
    }
    
    @directive("use server")
    let submit = (input: FormAction.t) => {
      await input->save
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions