-
-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusion about binding to external React components #685
Comments
How about this? Is it working? module ButtonExternalBroken = {
type props = { text: string }
@module("./ReadMoreButton")
external make: (props) => React.element = "default"
} |
@mununki Thanks for the correction! Your code is correct, but it still breaks for my use case—though I now have a better understanding of why that is. Your code breaks when binding to non-function components. My use case is binding to a component created with The error is thrown by the function call generated by the Rescript compiler when writing bindings this way, as you can see in your playground's code generated JS output. |
This should be working. module ButtonExternalBroken = {
type props = { text: string }
@module("./ReadMoreButton")
external make: React.component<props> = "default"
} This isn't really about JSX4, it's about binding React.component with props type. |
Ah! Yeah, the output of that looks much better. Thanks for the clarification. Now, do you think the website should have a section dedicated to bindings to external React components? It isn't necessarily obvious. |
Can you tell me what part of the current doc to go in? |
You can still access the old version of the rescript-react doc, I just can't seem to find it, can you tell me which part you are referring to? |
@mununki we should link this to the wider effort about revisiting bindings "using the language". I think we need to explore, then communicate best practices. We're currently at the stage of people saying "I've tried v11 and it's great", and can move to the next phase: documenting the new way of writing bindings. |
I was referring to the super old reason-react docs. Specifically, this section.
I think we could have a new page under the "guides" section of the rescript-react docs, called "Js Interop" |
@Emilios1995 I haven't seen that reason-react doc in a long time. Apparently it had something about react component binding, which is hard to find now. Thank you for reminding me. @cristianoc Agreed. |
The JSX 4 migration guide describes how it's possible to write components either writing the props type manually, or using the
@react.component
annotation.However, when binding to external components, I found that the only valid way of defining the bindings is with the
@react.component
attribute, since otherwise rendering the component results in a runtime error. Please look at this playground example.I'm not sure whether this is a bug, but if it's expected behavior, this should at least be documented somewhere. The question is where, though. The rescript-react docs used to have a section dedicated to binding to external components, but I seems like it's not there anymore.
If it's indeed a bug, I'd be happy to move this issue to the correct repo.
The text was updated successfully, but these errors were encountered: