You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
As I've been working more with enumerated states, "OPEN", "CLOSED" etc, and moving away from using bools like isOpen I was looking for a more explicit inline control flow for conditional rendering than ternary operators { isOpen ? <OpenState /> : <ClosedState> }.
I came across a pattern of using objects as inline switch statements:
I had never seen it used before and wondered whether there are any drawbacks? As I see it:
✅ Inline code so easy to see control flow
✅ Explicit declarations of states, with ability to add a fallback by adding || <Fallback />
✅ Easy to add new states by adding new object entries
❓ Does the creation of the object have a performance detriment over short-circuiting or ternaries?
The alternatives aren't perfect, ones I can see are:
✅ Easier to add new states
❌ Arguably harder to read with control flow jumping around in the document
❌ I've seen this pattern get really out of hand with 10+ render functions in one component
Would be great to hear your, or anyone else's thoughts on this!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hey Kent,
As I've been working more with enumerated states,
"OPEN"
,"CLOSED"
etc, and moving away from using bools likeisOpen
I was looking for a more explicit inline control flow for conditional rendering than ternary operators{ isOpen ? <OpenState /> : <ClosedState> }
.I came across a pattern of using objects as inline switch statements:
I had never seen it used before and wondered whether there are any drawbacks? As I see it:
✅ Inline code so easy to see control flow
✅ Explicit declarations of states, with ability to add a fallback by adding
|| <Fallback />
✅ Easy to add new states by adding new object entries
❓ Does the creation of the object have a performance detriment over short-circuiting or ternaries?
The alternatives aren't perfect, ones I can see are:
Inline ternary
✅ Good inline readability
❌ Difficult to add new states to the flow when requirements change
renderComponent()
function✅ Easier to add new states
❌ Arguably harder to read with control flow jumping around in the document
❌ I've seen this pattern get really out of hand with 10+ render functions in one component
Would be great to hear your, or anyone else's thoughts on this!
The text was updated successfully, but these errors were encountered: