title: Why is getState() not a function?
body: <p>I'm trying to create a simple Cart using Redux, but removeFromCart() function throws an error.</p>
  <p>I have created a <code>cartActions.js</code> file with two dispatch functions, <code>addToCart()</code> function that works as it should  and  <code>removeFromCart()</code>  function that returns <code>TypeError: getState is not a function</code>.</p>
  <p>How can I fix this problem ?</p>
  <p>This is the <code>cartActions.js</code> file:</p>
  <pre><code>import { ADD_TO_CART, REMOVE_FROM_CART } from &quot;../types&quot;;
  
  export const addToCart = (product) =&gt; (dispatch, getState) =&gt; {
    const cartItems = getState().cart.cartItems.slice();
    let alreadyExists = false;
    cartItems.forEach((x) =&gt; {
      if (x._id === product._id) {
        alreadyExists = true;
        x.count++;
      }
    });
    if (!alreadyExists) {
      cartItems.push({ ...product, count: 1 });
    }
    dispatch({
      type: ADD_TO_CART,
      payload: { cartItems },
    });
    localStorage.setItem(&quot;cartItems&quot;, JSON.stringify(cartItems));
    console.log(cartItems)
  };
  
  
  export const removeFromCart = (product) =&gt; (dispatch, getState) =&gt; {
    const cartItems = getState().cart.cartItems.slice()
      .filter((x) =&gt; x._id !== product._id);
    dispatch({
    type: REMOVE_FROM_CART, 
    payload: { cartItems },
    });
    localStorage.setItem(&quot;cartItems&quot;, JSON.stringify(cartItems));
  };
  </code></pre>
  <p>This is the error that I get:</p>
  <pre><code>    24 | 
    25 | export const removeFromCart = (product) =&gt; (dispatch, getState) =&gt; {
  &gt; 26 |   const cartItems = getState().cart.cartItems.slice()
    27 |     .filter((x) =&gt; x._id !== product._id);
    28 |   dispatch({
    29 |         type: REMOVE_FROM_CART,
  </code></pre>
  <p>The error occurs when the cart component is supposed to render.</p>
  <p>I have a function <code>openCart()</code> that alternate between rendering the &quot;Shop&quot; and &quot;Cart&quot; when I press the button the error occurs</p>
  <p>This is the <code>openCart()</code> function:</p>
  
  <pre class="lang-js prettyprint-override"><code>openCart = () =&gt; {
          this.setState({openCartStatus:!this.state.openCartStatus});
      } // the function starts  with  openCartStatus as false
  </code></pre>
  <p>The <code>cart.js</code> file is long but I think it’s  necessary to include  it for reference.
  I used react hooks for <code>cart.js</code>.</p>
  <p>this is the <code>cart.js</code>:</p>
  <pre><code>import React, { useRef } from 'react';
  import './cart.css'
  import { useIntersection } from 'react-use';
  
  import formatCurrency from '../../../util'
  import { Fade } from &quot;react-awesome-reveal&quot;;
  import { connect } from 'react-redux';
  import { removeFromCart } from '../../../actions/cartActions';
  
   function Cart (props) {
            
          const sectionRef = useRef(null);
  
          const intersection = useIntersection(sectionRef, {
              root: null,
              rootMargin: &quot;80%&quot;,
              threshold: 0.8,
          });
    
          const { cartItems } = props;
          return (
              &lt;div className=&quot;container&quot; &gt;
                  &lt;div className=&quot;cart_container&quot; ref={sectionRef}&gt;
                   &lt;div className=&quot;cart_icon_container&quot;&gt;
                       &lt;div  className={intersection &amp;&amp; intersection.intersectionRatio &lt; 0.5 ? &quot;cart_Icon&quot; : &quot;cart_Icon_Btn&quot;} onClick={() =&gt; {
                      props.openCart();
                      }}&gt;
                          &lt;img alt='cart-icon' src='./Images/icons8-shopping-bag-32.png' &gt;&lt;/img&gt;
                   &lt;/div&gt; 
                &lt;/div&gt; 
                 
  
                  {cartItems.length === 0 ? (
                   &lt;div className=&quot;cart cart_header&quot;&gt; 
                  Cart Is Empty
                  &lt;/div&gt;
                      ) : (
                  &lt;div className=&quot;cart cart_header&quot;&gt;
                       You Have {cartItems.length} Itames In The Cart{&quot;&quot;}
                  &lt;/div&gt;
                  )}
                  &lt;div&gt; 
                      &lt;div className=&quot;cart&quot;&gt;
                          &lt;Fade direction=&quot;up&quot; triggerOnce cascade duration=&quot;750&quot;&gt;
                          &lt;ul className=&quot;cart_items&quot;&gt;
                              {cartItems.map((item , index ) =&gt; (
                                  &lt;li key={index}&gt;
                                      &lt;div className=&quot;cart_image&quot;&gt;
                                          &lt;img src={item.image} alt={item.name}&gt;&lt;/img&gt;
                                      &lt;/div&gt; 
                  &lt;div className=&quot;ShopItem_details_discription&quot;&gt;
                      &lt;div className=&quot;productInfo_Container&quot;&gt;
                              &lt;div&gt; LOGO &lt;/div&gt;
                              &lt;div className=&quot;productInfo&quot;&gt;
                              &lt;h2&gt;{item.name}&lt;/h2&gt;
                                  &lt;p&gt;{item.info}&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div &gt;
                                  &lt;p&gt; Phone Number&lt;/p&gt;
                                  &lt;div className=&quot;flourType_Container&quot; &gt;
                                      {item.flourType.map((x)=&gt;(  
                                      &lt;div&gt;{&quot; &quot;}{x}&lt;/div&gt;
                                      ))}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                              
                          &lt;/div&gt;
                                      &lt;div className=&quot;cart_mengment&quot;&gt;
                                          {formatCurrency(item.price)}
                                          &lt;div className=&quot;btn_containar&quot;&gt;
                                              &lt;button onClick={() =&gt; props.addAmount(item)} className  = &quot;Btn&quot; &gt; + &lt;/button&gt;
                                              &lt;div className = &quot;ItemCounte&quot;&gt; {item.count}&lt;/div&gt;
                                              &lt;button onClick={() =&gt; props.subAmount(item, index)} className  = &quot;Btn&quot; &gt; - &lt;/button&gt;
                                          &lt;/div&gt;
                                          &lt;button className=&quot;cart_item_remove&quot; onClick={() =&gt; props.removeFromCart(index)}&gt;
                                              Remove
                                          &lt;/button&gt;
                                      &lt;/div&gt;
                                  &lt;/li&gt;
                              ))}
  
                          &lt;/ul&gt;
                          &lt;/Fade&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  {cartItems.length !== 0 &amp;&amp; (
               &lt;div className=&quot;cart&quot;&gt;
                      &lt;div className=&quot;total&quot;&gt;
                          &lt;div &gt;
                              TOTAL{&quot;   &quot;}
                              {formatCurrency(
                                  cartItems.reduce((a, c) =&gt; a + c.price * c.count, 0)
                              )}
                          &lt;/div&gt;
                          &lt;button className=&quot;proceed_Btn&quot; onClick={() =&gt; {
                              props.showCheckout();
                              }}&gt; 
                              Proceed
                          &lt;/button&gt;
                   &lt;/div&gt; 
               &lt;/div&gt;
               )} 
              &lt;/div&gt;
          &lt;/div&gt;
              
          )
      }
  
      export default connect((state) =&gt; ({
          cartItems: state.cart.cartItems,
          }),
          removeFromCart
      )(Cart);
      
  </code></pre>