Firebase를 사용하여 일부 데이터를 잡아 내 웹 앱에 표시하려하고 있지만 어떻게하는지 이해하지 못합니다. 나는 reduxThunk를 사용하고 있습니다. 오류가 발생했습니다. ID가 정의되지 않았습니다.. 이 내 구성 요소React-Redux - Firebase에서 데이터를 가져 오는 중
이 내 작업
행동이다
import React, { Component } from 'react';
import { connect } from 'react-redux';
import * as actions from '../actions';
class Trabalhos extends Component {
componentWillMount(){
this.props.fetchData();
}
renderList({id,tec,title}){
return(
<li className="list-group-item" key={id}>
<p>{title}</p>
<p>{tec}</p>
</li>
)
}
render(){
return (
<div>
<div className="trabalhos">
<div className="trabalhos_caixa">
<div className="row">
<div className="col-xs-12">
<ul className="no_pad">
{this.renderList()}
</ul>
</div>
</div>
</div>
</div>
</div>
);
}
}
function mapStateToProps(state){
return { fetch: state.fetch };
}
export default connect(mapStateToProps, actions)(Trabalhos);
trabalhos.js /하는 index.js
import Firebase from 'firebase';
import { FETCH_DATA } from './types';
const Data = new Firebase('https://portofoliofirebase.firebaseio.com');
export function fetchData(){
return dispatch => {
Data.on('value', snapshot => {
dispatch({
type: FETCH_DATA,
payload: snapshot.val()
});
});
}
}
이 내 하는 index.js입니다
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { Router, browserHistory } from 'react-router';
import reducers from './reducers';
import routes from './routes';
import * as **firebase** from 'firebase';
import **reduxThunk** from 'redux-thunk'
const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore);
const store = createStoreWithMiddleware(reducers);
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory} routes={routes} />
</Provider>
, document.querySelector('.container'));
이이 내 감속기입니다 하는 index.js
import { combineReducers } from 'redux';
import fetchReducer from './fetch_reducer';
const rootReducer = combineReducers({
fetch: fetchReducer
});
export default rootReducer;
Trabalhos 구성 요소가 소품을 가져 오는 위치는 어디입니까? 그게 연결 구성 요소가 될 작정입니까? –
업데이트했습니다! –
@Hseleiro 어디에서 오류가 발생합니까? 귀하의 firebase 응용 프로그램이 작동합니까? 문서에서 Firebase가 활성화되기 전에 initializeApp를 실행해야합니다. 또한, firebase.database(). ref()에서'.on()'을 호출하여 변경 사항을 수신해야한다. Firebase 인스턴스에서 직접'.on() '을 호출 할 수 없다고 생각합니다 (아래 링크 참조). https://firebase.google.com/docs/reference/js/firebase https://firebase.google.com/docs/database/web/read-and-write – Shane