new to react, have seen some of the similar title as below but still could not clarify with the error getting on the console saying Uncaught TypeError: this.state.stock.map is not a function
. When I use the similar code in the another api call then there is no such error coming. The code is as below for the same. If I am assigning data from the get method to stock the also its not working and giving the same issue. What is the problem ? a few links that I referred.
var StockData = React.createClass({
getInitialState: function() {
return {
stock: []
};
},
componentDidMount: function() {
this.serverRequest = $.get(this.props.source, function (data) {
var old = JSON.stringify(data).replace("//", ""); //convert to JSON string
var obj = JSON.parse(old); //convert back to JSON
console.log(obj);
this.setState({
stock: obj
});
}.bind(this));
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
return (
React.createElement("div",null,
React.createElement("ul",null,
this.state.stock.map(function (listValue){
return React.createElement("li",null,listValue.t,"( ",listValue.e," )-"," Current Price :",listValue.l_cur," Date :",listValue.lt
);
})
)
)
);
}
});
ReactDOM.render(React.createElement(StockData, { source: "http://www.google.com/finance/info?q=NSE:ATULAUTO,WIPRO,INFY" }),document.getElementById('proper-list-render3'));