Background Colour React | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

25th Aug 2019, 10:17 AM
Clueless Coder
Clueless Coder - avatar
2 Answers
+ 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
25th Aug 2019, 12:43 PM
Gordon
Gordon - avatar
+ 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
25th Aug 2019, 4:23 PM
Calviղ
Calviղ - avatar