title: Is there a way to use template literals for fetch request?
body: <p>I'd like to define a function that makes a fetch request based on its parameter so I can simplify the fetch calls inside componentDidMount(). I've tried the code below but it gives an Unexpected token error for the setState function. Is there a way to use the parameter of the function inside then()?</p>
  
  <pre><code> constructor() {
      super();
      // cases in date order from 1 to 5. Cases5 is the latest.
      this.state = {
        cases1: [],
        cases2: [],
        cases3: [],
        cases4: [],
        cases5: [],
      };
    }
  
  componentDidMount() {
      fetch("/cases/1")
        .then((res) =&gt; res.json())
        .then((cases1) =&gt; this.setState({ cases1 }));
  
      fetch("/cases/2")
        .then((res) =&gt; res.json())
        .then((cases2) =&gt; this.setState({ cases2 }));
  
      fetch("/cases/3")
        .then((res) =&gt; res.json())
        .then((cases3) =&gt; this.setState({ cases3 }));
  
      fetch("/cases/4")
        .then((res) =&gt; res.json())
        .then((cases4) =&gt; this.setState({ cases4 }));
  
      fetch("/cases/5")
        .then((res) =&gt; res.json())
        .then((cases5) =&gt; this.setState({ cases5 }));
    }
  
    fetchCaseData = (index) =&gt; {
      fetch(`/cases${index}`)
        .then((res) =&gt; res.json())
        .then((`cases${index}`) =&gt; this.setState({ `cases${index}` }));
    }
  
  
  </code></pre>