Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1948

Preact signals-react bindings (basic)

$
0
0

Nice work! I’m not up to date on signals - what’s stopping us from using it directly with Preact in ReScript? Is the “only” issue the same issues as with Solid, that the compiler can output code that breaks reactivity?

Nice job on the bindings too. One small thing you could change - currently, the actual type of the signal isn’t carried with the typings, so getValue/setValue is essentially any. By adding a type parameter to Signal.t and using that in your bindings, you’ll get the proper typings derived from the signal as it was created:

module Signal = {
  type t<'value>

  @module("@preact/signals-react") @new external make: 'value => t<'value> = "Signal"
  @get external getValue: t<'value> => 'value = "value"
  @set external setValue: (t<'value>, 'value) => unit = "value"
}

module EffectStore = {
  type t
}

@module("@preact/signals-react") external createSignal: 'value => Signal.t<'value> = "signal"
@module("@preact/signals-react") external useSignal: 'value => Signal.t<'value> = "useSignal"
@module("@preact/signals-react/runtime") external useSignals: unit => EffectStore.t = "useSignals"

Viewing all articles
Browse latest Browse all 1948

Trending Articles