React pattern for managing the kind of problem i have mentioned below?

Viewed 17
1 Answers

You can use inline styles, which you can set conditionally based on state or a variable value. So your div that is now:

<div className="flex mb-4">Color of Blood</div>

can be

<div style={ userSelectedAnswer === 'red' ? {backgroundColor: 'red'} : {} }>Color of Blood</div>

You'll want to review a write-up on inline styles in React to get an idea of how things work, and, for example, why I used camel-case for backgroundColor instead of 'background-color'.

Related