Consolidating Props #181
Replies: 3 comments
-
Some thoughts not sure if this is more complicated or if any of this is really possible. Shared Props
Personally, if neither (I almost like 2 more) above are not possible then I would be in the camp of letting the component handle the prop definitions and error handling then everything above would be a primitive object. I don't want to get in a situation where the PropType definition is maintained in 5 different places all with varying levels of compliance. Transforming DataHaving a global transformer that loads each component transformer. Possibly use the |
Beta Was this translation helpful? Give feedback.
-
After sitting with this a bit, I like where you're going. The consolidation of data and content structure makes sense to me. Today we have a Prop types feel related, even though they aren't exactly. Still, being able to see the shape of the entire application from one space does have some benefits — including being able to surface these in the playgrounds, and being able to reuse groups of validation rules. I also agree that if we can transform at the top level, that would be ideal. I think the first iteration of that is going to have to be fairly opinionated. We'll have to consider how this would work with data coming in from both Contentful and Forestry, along with how other CMSes may behave. There are a significant number of questions and hurdles involved here. I'm thinking the best path forward is for me to take a whack at it and discuss once I have an example of a working DSL for both prop types and transformers. |
Beta Was this translation helpful? Give feedback.
-
Considering this to be an exploration. Will reopen for comments after I've had some time to tinker. |
Beta Was this translation helpful? Give feedback.
-
One question and one issue have popped up on recent projects that have led to this proposal:
Question: How do we define pass-through props? Do we define their shape(s), or do we leave them simply as objects/arrays, and pass them through?
Issue: Regardless of the answer to that question, it's unlikely that we're going to define the entire shape of a template. And yet, there's some value in being able to see that shape.
Better Defining Props
When it comes to answering the question, I believe we should follow a pattern like so: Components (React components, i.e. including templates) are responsible for defining the shape(s) of the prop(s) they render to the screen, while pass-through props can be defined generically.
Now, say we implement and tend to follow that rule. That still doesn't solve the issue. In fact, it almost makes the issue more severe, as the props defined at the template level would seem fairly obscure and perhaps without the necessary context.
The path of least resistance here would be to do something like this ... Say I have a
<Card />
component that uses a<Button />
component. I could do this:The downside to this is that the component's job is to concern itself only with the rendering process, while transforming data is delegated to the component's controller (
index.js
). In this example, when the card is used, itwillshould be sent transformed data, assuming it was accessed from the controller. The problem is that the button isn't going to be transformed until it is used within the card.One way to get around this would be to transform further upstream. That seems like we could run into a hairy mess.
Rendering Defined Props
The last thing I'll add here is that ideally we'd be able to take the props definitions and render them somewhere, just as Storybook does. I know it can be done (because Storybook does it), but not exactly sure how.
Next Steps
So ... all that said, my proposal is:
Beta Was this translation helpful? Give feedback.
All reactions