【问题标题】:Reactjs Redux. Getting ' Invalid hook call' while using only while using connectReactjs Redux。仅在使用连接时使用时获取“无效的挂钩调用”
【发布时间】:2019-05-13 11:52:25
【问题描述】:

这是我的 Songs.js

class Songs extends React.Component {
    render() {
        return (
            <div>
                 Song List 
            </div>   
        );
    }   
} 
export default connect()(Songs);

App.js

const App = () => {
    return <div>
    <Songs/>
    </div>
};

export default App;

Index.js

ReactDOM.render(
<Provider store={createStore(reducers)}>
    <App /> 
</Provider>,
    document.getElementById("root"))

我正在尝试学习 React Redux。

在 Songs.js 文件中,我仅在使用连接时收到无效的 Hooks 错误。当我不尝试使用 redux connect 时,该应用程序运行良好

【问题讨论】:

  • 我无法复制。您能否分享导入语句,或澄清您是否正在采取导致错误的操作?

标签: javascript reactjs redux


【解决方案1】:

作为一个仅供参考,我能够复制并打开 react-redux 的问题。

问题: https://github.com/reduxjs/react-redux/issues/1303

【讨论】:

    【解决方案2】:

    确保您从 Redux 导入连接。

    import { connect } from 'react-redux';
    

    我假设如果connect 现在使用钩子,那么您正在使用与钩子 (>16.8) 兼容的 Redux 版本。

    确保ReactReact-Dom 是相同的版本。

    Might be related.

    The official docs.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 2021-12-07
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      相关资源
      最近更新 更多