Answer the question
In order to leave comments, you need to log in
Why does nothing come out when trying to display items from Firebase?
Hello everyone
I can not display items from the firebase. In AC - outputs, in reducer - outputs, but not in the component.
The code :
componentDidMount() {
const ideas = firebase.database().ref("items");
let arr = [];
ideas.on("value", snapshot => {
let items = snapshot.val();
for (let item in items) {
arr.push({
id: item,
text: items[item].text
});
}
});
this.props.renderIdeas(arr);
}
export function renderIdeas(ideas) {
return {
type: RENDER_IDEAS,
payload: ideas
};
}
export default function(state = [], action) {
switch (action.type) {
case RENDER_IDEAS:
return action.payload;
default:
return state;
}
}
render() {
var Items = this.props.ideas;
console.log(Items); //это выводит в порядке
for (var key in Items) {
console.log(key); //это уже не работает
}
}
Answer the question
In order to leave comments, you need to log in
The code in componentDidUpdate is not correct, you can fix it like this:
componentDidMount() {
const ideas = firebase.database().ref("items");
let arr = [];
ideas.on("value", snapshot => {
let items = snapshot.val();
for (let item in items) {
arr.push({
id: item,
text: items[item].text
});
}
this.props.renderIdeas(arr);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question