using console.log() in the render method can lead to trouble when dealing with asynchronous processes. You can try a simple verification in your console.log():
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Sure.
The render() method is called before componentDidMount(), so your console.log() is executed once before the functions in componentDidMount() are invoked. At this point, this.state.quotes is an empty array. So, console.log(this.state.quotes[1].quote) should throw an error because this.state.quotes = []. After componentDidMount() finishes, the render() method gets called again because state was updated when your component mounted. Since your console.log() is in the render method, it gets executed again. Using the logical && operator makes it so that your code only executes if a condition is met, protecting you from an error.