Background Colour React | SoloLearn: Learn to code for FREE!


Background Colour React

How can I change the background-colour of the body based on a condition in React. In this case, the time of the day. Edit: Another error, the image won't render. Does anyone know the correct syntax for <img> in JSX?

8/25/2019 10:17:06 AM

Clueless Coder

2 Answers

New Answer


1. Add styles.color assignment in each if code block, before return. 2. Your return img is never reached. Either advance them into return in each code block. or use a str to store the result of if, and add the img at last after if, before return.


To make good use of virtual dom, we should always use react state management and life cycle methods.. Check out this code how state management to auto update the dom from life cycle componentWillMount method: