This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
function App() { | |
const [astronauts, setAstronauts] = useState([]); | |
// setting the dependencies array in useEffect to an empty array | |
// ensures this fetch request only runs once instead of infinitely | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
// initialize the astronauts with an empty array | |
// to avoid running into null pointer exceptions | |
// after the first render, but before the componentDidMount() gets called |