How to use getInitialState on a new version of react loop data
old version of react works like this
getInitialState() {
return {
Thumbnails: [{ url: 'sample_url', name: 'sample_name' }] // this works fine
};
}
I am using laravel with gulp but when i include the data name and url
the loaded data makes some error. I can't Identify what causes the error
I load the render function in the component.
I watched the following instruction from laracast but they are using lower version on react and another thing is they load the render function in createClass.
My only Question is proper way to load state with JSON DATA
Thumbox.js
import React from 'react';
import ReactDOM from 'react-dom';
class Thumbox extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
// this fails
Thumbnails: [{
url: '#sample',
ename: 'Hello'
}]
// this works
// Thumbnails: []
}
}
render() {
var newThumbnail = function(tb) {
return <Thumbnail ename={tb.ename} url={tb.url} />
};
return (
<div>
<h1>Working with React</h1>
<ul>
{ this.state.Thumbnails.map(newThumbnail) }
</ul>
</div>
);
}
}
ReactDOM.render(<Thumbox />, document.getElementById('app-react'));
Thumbnail.js
import React from 'react';
import ReactDOM from 'react-dom';
class Thumbnail extends React.Component {
render() {
return (
<li>
<a className="thumb" href={ this.props.url } >{this.props.ename}</a>
</li>
);
}
}