-2

A question from a friend:

I have multiple usages for the same code, let's say a vertical HTML card. I change the title and a lot of data based on the react component.

it feels unnecessary performance-wise and for readability to use "if statement" multiple times on the same page, so wondering shall I just repeat the code or just keep going?

my code looking something like that:

<test value={this.state.welcomePage ? 
    "hello" : this.state.supportPage ?
    "Contact Us" : 
    "Something else" 
}/>
5
1

That's a horrible anti-pattern. Probably the correct answer is to pass the variable bits in through the component properties and component children. Another possibility would be to create a base component and subclass it for various uses. Hard to say more without a more complete sample.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.