Skip to content

Installation

Learn how to install rescript-signals and start building reactive applications.

Learn how to install and use rescript-signals in your project.

Installation

#

Install rescript-signals using your preferred package manager:

npm install rescript-signals

Configuration

#

Add rescript-signals to your rescript.json dependencies:

{
  "dependencies": [
    "rescript-signals"
  ]
}

Core Concepts

#

rescript-signals provides three main primitives for building reactive applications:

Signal

#

A reactive container that holds a value. When the value changes, all subscribers are automatically notified.

let name = Signal.make("World")
let greeting = Signal.get(name) // "World"
Signal.set(name, "ReScript")

Computed

#

A derived value that automatically recalculates when its dependencies change. Values are lazily evaluated and cached.

let count = Signal.make(5)
let doubled = Computed.make(() => Signal.get(count) * 2)
Computed.get(doubled) // 10

Effect

#

A side effect that runs when its dependencies change. Perfect for DOM updates, logging, or API calls.

let count = Signal.make(0)
Effect.run(() => {
  Console.log(`Count changed to: ${Signal.get(count)->Int.toString}`)
})
Was this page helpful?