Postanowiłem nauczyć się React i zacząłem od oficjalnego samouczka. Wszystko jest dobrze, dopóki nie dostać się do tego stanu mojego kodu:React Tutorial: TypeError: Nie można odczytać właściwości "rekwizytów" niezdefiniowanych
var CommentBox = React.createClass({
render:() => {
return (
<div className="commentBox">
<h1> Comments </h1>
<CommentList />
<CommentForm />
</div>
);
}
});
var CommentForm = React.createClass({
render:() => {
return (
<div className="commentForm">
Hello, world! I am a comment form;
</div>
);
}
});
var Comment = React.createClass({
rawMarkup:() => {
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
return {__html: rawMarkup};
},
render:() => {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2> // <--- [[[[[[ ERROR IS HERE ]]]]]]
<span dangerouslySetInnerHtml={this.rawMarkup} />
</div>
);
}
});
var CommentList = React.createClass({
render:() => {
return (
<div className="commentList">
<Comment author="Pete Hunt">This is one comment</Comment>
<Comment author="Jordan Walke">This is *another* comment yo</Comment>
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById('content')
);
Kiedy próbuję go uruchomić, pojawia się następujący błąd w DevTools: „TypeError: nie można odczytać własności«rekwizyty»undefined” i debugger zatrzymuje się na zaznaczonej linii (patrz kod). Kiedy najecham na "to" w {this.props.author} otrzymam podgląd obiektu, który ma właściwość "rekwizyty" i wszystko ...
Jestem naprawdę nowy, aby zareagować, więc jest to prawdopodobnie coś głupiego , ale kto wie ...
Mam nadzieję, że możesz pomóc!
Cheers, H.
Chcę dodać, że widziałem ten błąd niedawno ze względu na React narzędzi Dev. Po prostu chciałem to rzucić, ponieważ jest to najlepszy wynik Google. – Donald