Good afternoon, I get json from the server, I process it, but the call to render occurs 2 times.Google, make an empty object in the constructor.And if the object has no property, then undefined is returned, but I also have arrays, from which the application crashes.I attach the code. How to get the data out of the state? Is it possible to fetch in the render and write?
export default class Forma extends React.Component {
constructor(props) {
super(props);
this.state = { data: [] };
}
componentWillMount() {
fetch("http://localhost:3001")
.then(response => response.json())
.then(result => this.setState({ data: result }))
.catch(e => console.log(e));
}
render() {
const { data } = this.state;
return <h1>{console.log(data.goals[0].gs_id)}</h1>; //падает
}
}