Hi, I’m new to both ReScript and React, and excited to finally try React in a pragmatic functional setting. (Coming from a background of extensive experience with both Vue and Elm.)
I’ve just started playing around with a counter app and thought I’d try introducing an input field, but got stuck with the onInput
handler. I have a specific question about this, but also one about the recommended general approach for discovering/learning the API for ReScript packages.
So my specific problem is simply that onInput
expects ReactEvent.Form.t => unit
, and I don’t know how to get the input element’s value out of ReactEvent.Form.t
for use with a useState
update function. The example from React’s docs has e => updateFoo(e.target.value)
, so I tried this but evidently ReactEvent.Form.t
is not a record.
My next step was to look for the ReScript React API docs but I can find nothing beyond the (very useful) guide on rescript-lang.org. I gather that there is no central mechanism for package documentation, equivalent to Haddock or package.elm-lang.org. So I had a look in the rescript-react repo and found this in ReactEvent.resi
:
module Form: {
@get external target: t => {..} = "target"
}
That at least got me as far as realising that I should access target
via a function. As for its return type, I was stumped. Eventually I guessed that it might be an object, and finally arrived at ReactEvent.Form.target(e)["value"]
which compiles.
So my specific question: what is this {..}
syntax? Is it explained anywhere in the language docs?
And my more general question: what workflow could I have followed to arrive at the right answer here? Am I correct that there’s no standard documentation mechanism? For a package with no API docs, is my best bet to read .resi
files?
Ideally I feel I should be able to find the answer to a problem like this within VS Code. Is there a way to do that? It might be my unfamiliarity with VS Code (I’m an IntelliJ user), but I couldn’t find a way to navigate to or bring up any more information about the definition of ReactEvent.Form.t
.