使用firestoreConnect的react-redux-firebase错误 TypeError:未定义不是对象(正在评估“ this.store.firestore”)

教育网编2023-04-06 17:251780

如果您刚刚升级到React-Redux v6,那是因为react-redux-firebase与v6不兼容。

请参阅支持React-Redux v6。

解决方法

所以…我从react-redux-firebase使用firestoreConnect遇到错误,不确定发生了什么。这是我的index.js:

const createStoreWithFirebase = compose(
applyMiddleware(thunk.withExtraArgument({getFirebase,getFirestore})),reduxFirestore(firebaseConfig),reactReduxFirebase(firebaseConfig,{useFirestoreForProfile: true,userProfile: 'users',attachAuthIsReady: true}))(createStore);

const initialState = {};
const store = createStoreWithFirebase(rootReducer,initialState);

store.firebaseAuthIsReady.then(  => {
ReactDOM.render(<Provider store={store}><App/></Provider>,document.getElementById('root'));

serviceWorker.unregister ;
});

这是我组件的导出部分:

export default compose(
firestoreConnect([
    {'collection': 'allocables'},{'collection': 'solution'},{'collection': 'resources'}
]),connect(mapStateToProps,mapDispatchToProps)
)(Dashboard);

错误如下:

<div >TypeError: undefined is not an object (evaluating 'this.store.firestore')</div>

<div><div>componentWillMount</div><div ><span tabindex="0" >node_modules/react-redux-firebase/es/firestoreConnect.js:142</span></div><span><span ><pre ><code ><span data-ansi-line="true"><span></span><span> </span><span > 139 | </span><span>_createClass(</span><span >FirestoreConnect</span><span></span><span >,</span><span> [{</span><span></span></span><br><span data-ansi-line="true"><span></span><span> </span><span > 140 | </span><span>  key</span><span >:</span><span> </span><span >'componentWillMount'</span><span></span><span >,</span><span></span><span></span></span><br><span data-ansi-line="true"><span></span><span> </span><span > 141 | </span><span>  value</span><span >:</span><span> </span><span >function</span><span> componentWillMount  {</span><span></span></span><br><span data-ansi-line="true" ><span></span><span></span><span ></span><span >&gt;</span><span ></span><span></span><span > 142 | </span><span>    </span><span >var</span><span> firestore </span><span >=</span><span> </span><span >this</span><span></span><span >.</span><span>store</span><span >.</span><span>firestore</span><span >;</span><span></span><span></span></span><br><span data-ansi-line="true" ><span></span><span> </span><span >     | </span><span></span><span ></span><span >^</span><span ></span><span></span><span></span></span><span data-ansi-line="true"><span></span><span> </span><span > 143 | </span><span></span><span></span></span><br><span data-ansi-line="true"><span></span><span> </span><span > 144 | </span><span>    </span><span >if</span><span> (</span><span >this</span><span></span><span >.</span><span>firestoreIsEnabled) {</span><span></span></span><br><span data-ansi-line="true"><span></span><span> </span><span > 145 | </span><span>      </span><span >var</span><span> inputAsFunc </span><span >=</span><span> (</span><span >0</span><span></span><span >,</span><span> _utils</span><span >.</span><span>createCallable)(dataOrFn)</span><span >;</span><span></span><span></span></span></code></pre></span><button >View compiled</button></span></div>

评论区