T
T
tropicalfruit2018-03-20 02:52:27
React
tropicalfruit, 2018-03-20 02:52:27

Why does it give an error cannot read propery of undefined?

Hello everyone,
I just started learning React and ran into this problem. I receive data from the server (menu), the request returns the data correctly. Further through mapStateToProps I pass it to the props, in the console of the component the property is displayed normally. But if I try to call the map method in the renderer, then I get an error that it cannot read from undefined. If you call the log, then the properties of the component are displayed before rendering, and undefined when rendering. I can't understand why.
5ab04cb1e9c63489766172.png5ab04cbfdc0ba437223637.png5ab04cce861f8016499462.png5ab04cdde38c5328117619.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-03-20
@tropicalfruit

Apparently, you do not set an empty array items in initialState or destroy it in the reducer in the FETCH_MENU case . Can't say for sure without the reducer code. But I think that's the point. For the future. Attach code examples to the question, not screenshots. And examples of exactly the code that causes the error, and not some other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question