https://codesandbox.io/s/gifted-newton-wr2ssp?file=/src/App.js When user clicks the check answer button I want to change the style of that particular div to red or green color based on correct or wrong answer. But don't know how to do it in react.
https://codesandbox.io/s/gifted-newton-wr2ssp?file=/src/App.js When user clicks the check answer button I want to change the style of that particular div to red or green color based on correct or wrong answer. But don't know how to do it in react.
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'.