gpt4 book ai didi

reactjs - useSelector 无法从 'react-redux' 导出

转载 作者:行者123 更新时间:2023-12-04 09:06:02 25 4
gpt4 key购买 nike

我有一个错误提示 Can't import 'UseSelector' from react-redux。我正在做的是一个名为 Getting started 的小项目

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from './store/reducers/rootReducer'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import {createFirestoreInstance, reduxFirestore, getFirestore } from 'redux-firestore'
import { ReactReduxFirebaseProvider, getFirebase, reactReduxFirebase } from 'react-redux-firebase';
import firebase from 'firebase/app'
import fbConfig from './config/fbConfig'
import { useSelector } from 'react-redux'
import { isLoaded } from 'react-redux-firebase';



`
const store = createStore(rootReducer,
compose(
applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
reduxFirestore(fbConfig),
reactReduxFirebase(fbConfig, {attachAuthIsReady:true, firebase:'firebaseReducer'}) )
);


const rrfProps = {
firebase,
config: fbConfig,
dispatch: store.dispatch,
createFirestoreInstance,
userProfile: 'users', // where profiles are stored in database
presence: 'presence', // where list of online users is stored in database
sessions: 'sessions'
}




function AuthIsLoaded({ children }) {
const auth = useSelector(state => state.firebase.auth)
if (!isLoaded(auth)) return <div>Loading Screen...</div>;
return children
}

store.firebaseAuthIsReady.then(() => {



ReactDOM.render(
<Provider store={store}>
<ReactReduxFirebaseProvider {...rrfProps}>
<AuthIsLoaded>
<App />
</AuthIsLoaded>
</ReactReduxFirebaseProvider>
</Provider>,
document.getElementById('root'));
serviceWorker.unregister();


})

我试过重新启动 npm start,再次安装 react-redux,然后重新启动 npm start,运行 npm install 并关闭 Vscode,然后重新打开它。我试过了,我很困惑为什么它不起作用,但请帮我解决这个问题,谢谢 :D。

最佳答案

React Redux hooks were first added in v7.1.0所以如果你像你说的那样使用 React Redux v6.14.6,你就不能导入 useSelector 钩子(Hook)。

看起来你正在做一个类似教程的项目,所以我想你对包版本没有任何限制,你可以更新它而不会出现重大问题。请注意 React Redux 7.1 requires React 16.8.3 or later ,因此还要检查 package.json 文件中的 React 版本。

运行:

npm uninstall react react-redux
npm i react react-redux

然后检查你的 package.json 如果 dependencies 条目包含 "react-redux": "^7.2.1"“ react ”:“^16.13.1”

关于reactjs - useSelector 无法从 'react-redux' 导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63446373/

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