[Sketch] Mad science idea for auto-binding @module components #4762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today if you use 3D you need to pass the fragment you got, and your loader to
<MatchContainer />
to render it. Match container looks up the module via your loader, adds the fragment spread to the props you pass to<MatchContainer />
and uses those together to render your component.There's a major problem with that which is that the props you pass to MatchContainer are not typesafe because it is not currently aware of the prop types of the component(s) it might render.
There are other ways we could address this, but I wanted to explore the idea of having Relay return a pre-bound component for you. I think this is not a good direction for Relay today but some folks were interested so I wanted to share.
Code would end up looking something like this:
Pros
Cons
There are considerable downsides (Which I think outweigh the pros today) to consider:
@match
where there may be one of many components that match. How do you make props typesafe there? Require the user to refine which type they got? Require them to all match? Would need to figure that out.@module
component. Which would require some contract like fragments and components must be defined in the same file and the component must be the default export. Hard to enforce today since Relay still does not fully parse JS (soon maybe?).Acknowledgement: While not directly inspired by Isograph, I think this arrives at the same type of API as Isograph, which is cool! @rbalicki2