I have a pull request and this pr is being reviewed by co-worker.
Context
I'm using React and a specific component has ternary operator within component like below.
const ExampleComponent = (): React.ReactElement => {
return (
<div onClick={condition ? handlerA : handlerB}>
<span>{condition ? textA : textB}</span>
{condition ? <ChildA /> : <ChildB />}
</div>
);
}
In above code, my co-worker suggested like below.
const ComponentA = (): React.ReactElement => {
return (
<div onClick={handlerA}>
<span>{textA}</span>
<ChildA />
</div>
);
}
const ComponentB = (): React.ReactElement => {
return (
<div onClick={handlerB}>
<span>{textB}</span>
<ChildB />
</div>
);
}
const ExampleComponent = (): React.ReactElement => {
return (
<>{condition ? <Component A /> : <Component B />}</>
);
}
My opinion : can reduce duplication of tag, classname, text.
co-worker opinion : readability is better.
I thought deeply about these talking, but couldn't conclude which is the right way to make code clean.
Question
How can I decide which structure is better? Thanks for your reading!