Error of problem: TypeError: _this2.state.navigation[i] is undefined
You should use the callback in setState
if you want to do that because it is async. Please refer to the following link to get more info:
https://reactjs.org/docs/react-component.html#setstate
Another alternative is to set the state only once instead of doing it multiple times. You don't need to put all that info in the state only to update one value. And even if you do need all that info, you can use one setState
call instead of 3 like you are doing. Just set variables with the values that you want to set and do one update.
setState
is asynchronous, so you can't dothis.setState({ navigation: data.val() })
and expect it to be set inthis.state
in the following statement. Please include your code in text format instead of as images. – Tholle Feb 22 '19 at 11:56