React,Redux:Uncaught ReferenceError:未定义帖子

时间:2017-02-05 23:50:59

标签: javascript reactjs firebase firebase-realtime-database redux

基本上我有一个import语句,它接受一个文件中保存的一些JSON数据,我现在从firebase读取,并且我试图将返回数据的值传递给defaultstate {},但是我收到了上面的内容提到了错误消息。我该如何解决这个问题?:

store.js

import { createStore, compose, applyMiddleware } from 'redux';
import { syncHistoryWithStore } from 'react-router-redux';
import { browserHistory } from 'react-router';
import thunk from 'redux-thunk';
import * as firebase from 'firebase';

// import the root reducer
import rootReducer from '../reducers/index';

//Firebase configuration details and initialisation
import { Firebase_Config } from '../config/config';
firebase.initializeApp(Firebase_Config);
const rootRef = firebase.database();
const refPosts = rootRef.ref('posts');

refPosts.on("value", snapshot => {
  const posts = snapshot.val(); // I wish to pass this into defaultState{}
}, errorObject => {
  console.log("The read failed: " + errorObject.code);
});

// Get initial state of all comments and posts
import comments from '../config/comments';
// import posts from '../config/posts';

// create an object for the default data
const defaultState = {
  posts : posts, // I wish to pass in the snapshot value here
  comments
};

0 个答案:

没有答案