I am new to Redux and firebase and I have 2 documents under projects collection. However, I am unable to retrieve those collections. Here is my code,
fbConfig.js:
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
const firebaseConfig = {
... // This is correct!
};
firebase.initializeApp(firebaseConfig);
firebase.firestore();
export default firebase;
Component class (Dashboard.js):
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {firestoreConnect} from 'react-redux-firebase';
import {compose} from 'redux';
class Dashboard extends Component {
render() {
const {projects} = this.props;
...
}
}
const mapStateToProps = state => {
console.log(state);
return {projects: state.firestore.ordered.projects};
};
export default compose(
connect(mapStateToProps),
firestoreConnect(() => ['projects'])
)(Dashboard);
Here is my rootReducer.js:
import authReducer from "./authReducer";
import projectReducer from "./projectReducer";
import {combineReducers} from "redux";
import {firestoreReducer} from "redux-firestore";
const rootReducer = combineReducers({
auth: authReducer,
project: projectReducer,
firestore: firestoreReducer
});
export default rootReducer;
When I run the react project, It does not show any data. When I open the console, I see that state.firestore.ordered
is an empty object, as well as state.firestore.data
. Where am I going wrong?
EDIT 1:
Attaching my code for projectReducer.js:
const initState = {
projects: [
{id: 1, title: 'blah 1', content: 'blah blah 1'},
{id: 2, title: 'blah 2', content: 'blah blah 2'},
{id: 3, title: 'blah 3', content: 'blah blah 3'},
]
}
const projectReducer = (state = initState, action) => {
switch(action.type) {
case 'ADD_PROJECT':
console.log('Created project', action.project);
break;
case addProjectError:
console.log('Error on creating project', action.error);
break;
default:
break;
}
return state;
};
export default projectReducer;
Thy to check middleware in store definition. There is store index.js in my case that works with Firebase Firestore: