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

+2

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? https://code.sololearn.com/W714mbHH6290/?ref=app

8/25/2019 10:17:06 AM

Clueless Coder

2 Answers

New Answer

+1

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. https://code.sololearn.com/WhzetWWe0Z6G/?ref=app

+3

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: https://code.sololearn.com/Wwua1yjN2B6x/?ref=app