Mam klasę reakcji, która przechodzi do interfejsu API, aby uzyskać zawartość. Mam potwierdzone dane wraca, ale to nie jest re-rendering:Komponent reagujący nie renderuje się ponownie przy zmianie stanu
var DealsList = React.createClass({
getInitialState: function() {
return { deals: [] };
},
componentDidMount: function() {
this.loadDealsFromServer();
},
loadDealsFromServer: function() {
var newDeals = [];
chrome.runtime.sendMessage({ action: "findDeals", personId: this.props.person.id }, function(deals) {
newDeals = deals;
});
this.setState({ deals: newDeals });
},
render: function() {
var dealNodes = this.state.deals.map(function(deal, index) {
return (
<Deal deal={deal} key={index} />
);
});
return (
<div className="deals">
<table>
<thead>
<tr>
<td>Name</td>
<td>Amount</td>
<td>Stage</td>
<td>Probability</td>
<td>Status</td>
<td>Exp. Close</td>
</tr>
</thead>
<tbody>
{dealNodes}
</tbody>
</table>
</div>
);
}
});
Jednakże jeśli dodać debugger
jak poniżej, newDeals
są wypełniane, a następnie raz ja nadal widzę dane:
loadDealsFromServer: function() {
var newDeals = [];
chrome.runtime.sendMessage({ action: "findDeals", personId: this.props.person.id }, function(deals) {
newDeals = deals;
});
debugger
this.setState({ deals: newDeals });
},
to właśnie dzwoni lista promocje:
var Gmail = React.createClass({
render: function() {
return (
<div className="main">
<div className="panel">
<DealsList person={this.props.person} />
</div>
</div>
);
}
});
Duh! Powinienem był wiedzieć, że tak było, kiedy linia debuggera je naprawiła. Wiązanie (to) było tym, co przeoczyłem, gdy po raz pierwszy spróbowałem. Dzięki, świetny szczegółowy komentarz! – brandonhilkert