Else statement #131
-
Hi, In Here is an example.
How would to handle such a situation with gomponents? Could a Same but different, how would you handle a loop on a range? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Basically, negate the conditional expression: func component(condition bool) g.Node {
return Div(
g.If(condition, …),
g.If(!condition, …),
)
} Instead of looping, use Map. Or is there something you need that you don't get from looping? |
Beta Was this translation helpful? Give feedback.
-
Great examples, thanks for providing those. They answer my concerns! |
Beta Was this translation helpful? Give feedback.
-
Thank you @markuswustenberg for providing a simple solution to this. I came across this in a search for If/Else functionality too. I often find myself writing:
Whilst we could all add a simply utility function to our projects, I wonder whether it is such a common need that it might be worth adding to gomponents? A possible function signature:
Happy to contribute but unsure whether this aligns with the ethos of the lib? I, personally, find myself wanting this in gomponents. |
Beta Was this translation helpful? Give feedback.
Basically, negate the conditional expression:
Instead of looping, use Map. Or is there something you need that you don't get from looping?