시작 ReactJS 그리고 Firebase를 데이터베이스로 사용하여 데이터를 수집하려고합니다. 이 오류로 인해 2 일 동안 멈추었습니다. "null의 setState '속성을 읽을 수 없습니다.null의 속성 'setState'를 읽을 수 없습니다
Firebase에서 데이터를 읽을 수는 있지만 표시 할 수는 없습니다 ... 무엇을해야할지 모르겠습니다. 수행 this
아직 사용할 수 없기 때문에 당신은 생성자에서 this.setState
을 사용할 수 없습니다
import React from 'react';
import ProductList from '../Product/ProductList';
import Firebase from 'firebase';
class HomePage extends React.Component {
constructor() {
super();
this.state = {
productList: []
}
var firebaseRef = new Firebase('https://codehunt-one.firebaseio.com/');
firebaseRef.child("products").on('value', function(snapshot) {
var products = snapshot.val();
console.log(products);
this.setState({
productList: products
})
});
}
render() {
return (
<section>
<header>
<img src="img/banner.jpeg" width="100%" />
</header>
<section>
<section className="container">
{this.state.productList
?
<ProductList productList={this.state.productList}/>
:
null
}
</section>
</section>
</section>
);
}
}
export default HomePage;
가 좋아, 지금은이 오류가 발생했습니다 : 형식 오류 : this.props.productList.map이 아마 기능 –
아니다 productList가 배열이 아닌 무언가에 할당되었음을 의미합니다. snapshot.val()이 배열을 예상대로 반환하지 않았을 수 있습니까? – owerme