Skip to content
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

Open
Emilios1995 opened this issue May 17, 2023 · 9 comments
Open

Confusion about binding to external React components #685

Emilios1995 opened this issue May 17, 2023 · 9 comments

Comments

@Emilios1995
Copy link
Contributor

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.

@Emilios1995
Copy link
Contributor Author

@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 styled-components. I'm not sure how those are implemented, but I'm getting an error saying that the component is not callable.

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.

@Emilios1995
Copy link
Contributor Author

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.

@mununki
Copy link
Member

mununki commented May 19, 2023

Can you tell me what part of the current doc to go in?

@mununki
Copy link
Member

mununki commented May 19, 2023

The rescript-react docs used to have a section dedicated to binding to external components, but I seems like it's not there anymore.

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?

@cristianoc
Copy link
Contributor

@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.

@Emilios1995
Copy link
Contributor Author

Emilios1995 commented May 19, 2023

The rescript-react docs used to have a section dedicated to binding to external components, but I seems like it's not there anymore.

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?

I was referring to the super old reason-react docs. Specifically, this section.

Can you tell me what part of the current doc to go in?

I think we could have a new page under the "guides" section of the rescript-react docs, called "Js Interop"

@mununki
Copy link
Member

mununki commented May 19, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants