每当我尝试在我的 react/redux 应用程序中使用 getState() 方法时,我都会收到此错误 getState() 不是函数的原因是什么?

问题描述

    TypeError: getState is not a function

  32 | 
  33 | export const removeFromCart = (product) => (dispatch,getState) => {
> 34 |      getState() 
  35 |     const cartItems = getState().cart.cartItems.slice().filter(
  36 |         (x) => x._id !== product._id
  37 |         );`enter code here`
View compiled
▶ 29 stack frames wer

解决方法

你需要像这样将 getState 赋值给 var:

const state = getState() ;