Uh oh!
There was an error while loading. Please reload this page.
Add internal ConditionalWrapper component - #4095
Conversation
|
size-limit report 📦
|
joshblack
commented
Dec 20, 2023
I think one downside of this technique that wouldn't exist if using ternaries or refactoring into smaller components is that things are evaluated even if the condition is false-y. So when we have code like: <ConditionalWrapperif={conditional}sx={{/* ... */}}><ChildComponentsx={{/* ... */}}><SomeOtherChild/></ChildComponent></ConditionalWrapper>Things like the <ConditionalWrapperif={hasTheThing}>{/* this will be evaluated even if `hasTheThing` is false-y */}{/* it also won't be narrowed so it will require a guard */}<SomeComponent>{hasTheThing.title}</Subcomponent/></ConditionalWrapper>I think with this in mind I'd love to encourage alternatives that we could use instead that wouldn't have these limitations. Ternaries are definitely something that come to mind but they are so inconvenient/hard to understand with a lot of nesting. In those cases, it may be worth us trying to refactor things into sub-components that are local to the file to help avoid the challenges above while still being able to reason about why things are rendering. |
langermank
commented
Dec 21, 2023
Putting this on pause as we look into alternative solutions ✨ |
mperrotti
commented
Dec 21, 2023
Dismissing my review until we agree on a path forward from this discussion |
mperrotti
commented
Dec 21, 2023
It's worth mentioning that we use a similar component in |
Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days. |
mperrotti
commented
Mar 12, 2024
Reopening since we have a path forward for live region support: #4313 |
* move to internal comp * lint --------- Co-authored-by: Mike Perrotti <mperrotti@github.com>
I have a use case for this in
Button, and we have this same component in PVC.I renamed it to match up with PVC, but no changes beyond that. I've also tested it already in #3582.