gpt4 book ai didi

reactjs - React-redux useDispatch() Uncaught TypeError

转载 作者:行者123 更新时间:2023-12-03 15:24:32 29 4
gpt4 key购买 nike

我正在尝试创建一个简单的组件来使用 React Redux Hook useDispatch 调度操作- 我得到一个错误。我已将组件修剪到发生错误的位置。它在调用 useDispatch 函数时发生。

import { useDispatch } from 'react-redux'

const MyComp = () => {
useDispatch()
return null
}

export default MyComp

这是我在开发控制台中看到的错误:
Uncaught TypeError: Object(...) is not a function
at MyComp (MyComp.js?cc4c:4)
at renderWithHooks (react-dom.development.js?d018:12938)
at mountIndeterminateComponent (react-dom.development.js?d018:15020)
at beginWork (react-dom.development.js?d018:15625)
at performUnitOfWork (react-dom.development.js?d018:19312)
at workLoop (react-dom.development.js?d018:19352)
at HTMLUnknownElement.callCallback (react-dom.development.js?d018:149)
at Object.invokeGuardedCallbackDev (react-dom.development.js?d018:199)
at invokeGuardedCallback (react-dom.development.js?d018:256)
at replayUnitOfWork (react-dom.development.js?d018:18578)

我已经进一步修剪了这个,所以 react 树中没有 parent 。
const store = configureStore()

ReactDOM.render(
<Provider store={store}>
<MyComp />
</Provider>,
document.getElementById('root')
)

模块版本
    "react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",

最佳答案

就我而言,我正在做:

import { useDispatch } from 'react'

代替:

import { useDispatch } from 'react-redux'

🤦‍♂️

关于reactjs - React-redux useDispatch() Uncaught TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57277698/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com