-
Notifications
You must be signed in to change notification settings - Fork 208
Improve changing the underlying component that's rendered #135
Comments
Ok, so I created this as a proof of concept way to do this without building something into glamorous. However, it's a bit of a hack and what's worse is it results in a full render of the original component which could have unintended side effects. So I think that we'll want this built-into glamorous 👍 Anyone wanna work on this? Here's where we render the component. We'll basically want to add to this I'm pretty sure that's all that needs to happen. We'll want to have a handful of tests for this functionality. I would be cool if we make a brand new file for these tests: Who wants this one? |
@kentcdodds would love to try |
Unable to get this working, how will I change values of |
I would create a new function declaration here. Then on the line after this one I would add another object parameter to the So it'll look like: // ...
Object.assign(
GlamorousComponent,
getGlamorousComponentMetadata({
comp,
styles,
rootEl,
forwardProps,
displayName,
}),
{withComponent},
)
return GlamorousComponent
}
}
function withComponent(
comp,
{
rootEl = comp.comp ? comp.comp : comp,
displayName = `glamorous(${getDisplayName(comp)})`,
forwardProps = GlamorousComponent.forwardProps
} = {}
) {
Object.assign(GlamorousComponent, {comp, rootEl, displayName, forwardProps})
}
function getGlamorousComponentMetadata({
// ... I'm pretty sure that's actually all that you'd need to do. Could be more to it... But from there it's just writing a few tests 😄 Let me know if you need anymore help! |
did nearly the same thing but GlamorousComponent is not defined in scope |
Ah, put it up a couple lines so it's in the right closure :) |
Moving it up a scope does not solve the issue. It changes the tag of the actual component too |
Why don't you go ahead and push what you have in a PR and we'll give it a look. |
* feat(glamororus): withComponent support Closes #135 * test(withComponent): add more test for with-commponent
In the v2 styled-components announcement blogpost, they introduced a new API called the
.extend
helper. We actually do not need this because ourglamorous(Component)
already behaves in this way. So that's a relief (however we may be able to improve docs so this is more clear 🤔).But they also introduced a
.withComponent
API which I think is kinda handy:For us, to do this now is not really ergonomic:
Should we add a
withComponent
API?Please leave a 👍 (yes) or 👎 (no, don't add the new API)
The text was updated successfully, but these errors were encountered: