I’m migrating to newer ReScript tooling and started getting the error The value makeProps can't be found in .... Throughout my code I’ve been calling makeProps to generate the properties used to instantiate React components. According to these docs, makeProps does not exist anymore. Previously it seemed to be an automatically generated function I could use.
Is makeProps a Rescript-only thing? Or is this a React thing?
According to the docs above, it tells me how to migrate. I don’t understand this because it is telling me to change @obj external..., which I never wrote for my components, to something else. I’m just not understanding this because in the recommended migration solution it doesn’t look like there is a makeProps function after I do those steps. After I do the recommended migration, will I have access to a “makeProps” function anymore? Or do I need to define a type for the props just like any other type I use? Sorry just not understanding this.
Why do you fell you need to do this? The makeProps calls were generated automatically by the V3 JSX transforms, so you seldom needed to call them directly, provided you used ReScript React components via JSX in ReScript (IOW, no interop with JS components was involved).
Yes.
No.
Yes This is what the V4 example is about: you define a props type as a record (just like you would in TypeScript):
// V4
module M = {
type props<'msg> = {msg: 'msg}
let make = props => <div> {React.string(props.msg)} </div>
}
But the example is for migrating a handwritten component, if you need one of those for some reason. If you don’t, it’s simpler to make use of the @react.component decorator and rewrite the above as:
module M = {
@react.component
let make = (~msg) => <div> {React.string(msg)} </div>
}
// usage:
let _ = <M msg="Hi there" />
So the usage is the same, but previously the compiled JS would call M.makeProps to create an object that it would pass to React.createElement and now instead of that call, ReScript compiles directly to an object literal (see the playground).