React: Known pain-points around signal initialization

Hello, I’m running into an issue in React where I do (essentially):

React.S.(value (map f some_signal))

And this blows up because the signal returned by map is not initialized.

In reality, I’m doing ReactiveData.from_signal here, which uses React.S.value.

I saw in the Note repo, in talking about the Pro’s of Note:

  • Provides (hopefully) a better combinator set. Especially with respect to the pain point of signal initialization in React: in Note, due the pull based strategy, {E,S}.value is safe and sound to use.

What is going on here? Is there a way around it in React?

I found Your production web stack in 2020 - #10 by smondet which references the .value traps.

In my case I tried changing it to ReactiveData.from_signal (React.S.fmap f [] some_signal) which at least avoid the exception, but the list doesn’t seem to change with my signal getting updated (at least in my test case).

value is unsafe in React the proper way of getting a signal value is to bind.

Thank you.

Is there a safe way to combine ReactiveData.Rlist.from_signal? Or is that function inherently unsafe and should be avoided?

I don’t know I’m not the author of ReactiveData.

Whoops, sorry, I made an assumption.

What I’ve done, which seems to work is something like:

let (signal, set) = create default_value in
let workaround = map (fun v -> set v) signal in
from_signal @@ map (fun v -> stuff I want to do) signal

Not ideal but the create in the version of React I’m using seems to guarantee there is a value there so it unblocks me until I find a more elegant solution.

Thank you for the quick response, @dbuenzli