title: React-Redux - Parsing error: Can not use keyword 'await' outside an async function
body: <p>I am working on a React application and I am using Redux to store the state. I have the following code:</p>
  
  <p>menu.types.js:</p>
  
  <pre><code>export const FETCH_CATEGORY_RANKS = "FETCH_CATEGORY_RANKS";
  </code></pre>
  
  <p>menu.actions.js:</p>
  
  <pre><code>    import { apiUrl, apiConfig } from '../../util/api';
      import { FETCH_CATEGORY_RANKS } from './menu.types';
  
      export const fetchCategoryRanks = menu =&gt; async dispatch =&gt; {
      console.log("Printing menu (fetch category ranks)");
      console.log(menu);
  
      menu.map(category =&gt; {
          const options = {
              ...apiConfig(),
              method: 'PUT',
              body: JSON.stringify(category)
          }
          const response = await fetch(`${apiUrl}/category/${category._id}`, options)
          let data = await response.json()
          if (response.ok) {
              console.log("It got sent")
          } else {
              alert(data.error)
          }
      });
  
      dispatch({ type: FETCH_CATEGORY_RANKS, menu });
  
  }
  </code></pre>
  
  <p>menu.reducer.js:</p>
  
  <pre><code>// import INITIAL_STATE from './menu.data';
  import { FETCH_CATEGORY_RANKS } from './menu.types';
  
  const INITIAL_STATE = []
  
  
  export default (state = INITIAL_STATE, action) =&gt; {
      switch (action.type) {
          case FETCH_CATEGORY_RANKS:
             return state;
          default:
              return state;
      }
  }
  </code></pre>
  
  <p>In my <code>fetchCategoryRanks</code> action creator, I am looping through the <code>menu</code> array which is given as a parameter to this function. For each category object in the menu, I am sending information about this category to a server through making a PUT request using fetch.</p>
  
  <p>However, I am getting the following error:</p>
  
  <p><a href="https://i.stack.imgur.com/umCX4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/umCX4.png" alt="enter image description here"></a></p>
  
  <p>I am not sure why I am getting this error or how to resolve it. Any insights are appreciated.</p>