我正在使用react native app从firebase数据库中获取数据。我们的想法是,一旦从FirebaseDB收到数据,就会发出一个操作来初始化def function_y():
import main
dostuff...
main.object.bye() #object from Main.py
dostuff...
main.function_x() #function from Main.py
。问题是收到数据时不会触发调度。我错过了什么?
我正在使用redux-thunk中间件。
// database.js
store.appState
// actions.js
import * as firebase from 'firebase'
const config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
}
const Database = firebase
.initializeApp(config)
.database()
.ref()
export default Database
// container.js
import database from 'database'
const setInitDataFromFirebase = data => {
return ({
type: SET_DATA_INIT,
payload: {
data
}
})
}
export const loadAction = () => {
return dispatch => {
Database.once('value', snapshot=>{
console.log(snapshot.val()) // i get the log with correct data
dispatch(setInitDataFromFirebase(snapshot.val())) // this is not dispatched
})
}
}
答案 0 :(得分:0)
我弄明白了。事实证明,当我导入redux-thunk时,我做了一个非常基本的拼写错误。我应该做的
import ReduxThunk from 'redux-thunk'
const store = createStore(
RootReducer,
applyMiddleware(ReduxThunk, logger)
)
我错误地做了什么
import thunk from 'redux-thunk'
const store = createStore(
RootReducer,
applyMiddleware(thunk, logger)
)