Greetings to all!
It seems everything should work fine, but when compiling I get the error: Uncaught TypeError: Cannot read property 'state' of undefined .
The details are written:
React.createElement( 'ul', { id: 'list-drafts' }, undefined.state.drafts.length > 0 ? undefined.state.drafts.map(function (draft) { return React.createElement( 'li', That part of the source in question:
var ReviewsWidgetSidebar = React.createClass({ getInitialState: () => { return { drafts: [] }; }, componentDidMount: () => { GetApi.call('data/get-drafts', {}, function (drafts) { this.setState({ drafts: drafts }); }); }, render: () => { return ( <div> <ul id="list-drafts"> { (this.state.drafts.length > 0) ? this.state.drafts.map((draft) => { return ( <li data-id={draft.id} data-is-unread={draft.is_unread}> {draft.text} </li> ); }) : ` <li style={{textAlign: 'center'}}> Loading... <img src="/img/loading.gif" /> </li> ` } </ul> </div> ); } }); I tried to correct the error in different ways (make the mapping higher, override this with another variable, etc.), but it does not work ...
Tell me what's wrong, how to fix it?
React.Componentinstead ofReact.createClass? - YozhEzhiReact.createClassdocumentation. I now remember that it will soon be depricated. - YozhEzhi