const Component = () => {
let x = 1
switch(x) {
case 1:
return (
<Component1 />
<Component2 />
)
case 2:
return (
<Component1 />
<Component3 />
)
}
}
In the above code, in case 1
, Component1
and Component2
are rendered while in case 2
, Component1
and Component3
are rendered.
Is there a way to minimize repeated code by using a switch
statement inside a single return statment eg.
const Component = () => {
let x = 1
return (
<Component1 />
switch(x) {
case 1:
<Component2 />
case 2:
<Component3 />
}
}