I'm trying to pass and array of objects, fetched fro get request, to component's state, which has an array. I can successfully pass an array of numbers, or really anything but objects cause when i do that i recieve this: error_image.png
Check out my .js files below, thanks.
comment_item.js :
import React from 'react';
import axios from 'axios';
export class CommentItem extends React.Component {
constructor(props) {
super(props);
this.state = {
comments: []
};
}
componentWillMount() {
axios.get('api/v1/trip/2/comment/')
.then(response => {
const comments = [{a: 2, b: 4}, {a: 1, b: 3}]; //response.data should be here, but for your convenience I've put array of objects
this.setState({comments});
});
}
render() {
return (
<div>
<ul>
<li>
{this.state.comments[0].a}
</li>
</ul>
</div>
);
}
}
comment.js :
import React from 'react';
import Paper from 'material-ui/Paper';
import Divider from 'material-ui/Divider';
import List from 'material-ui/List/List';
import {CommentItem} from './comment_item';
import {CommentForm} from './comment_form';
const styles = {
paper: {
paddingLeft: 15,
paddingRight: 15,
paddingBottom: 15,
marginLeft: 15,
marginRight: 15,
marginBottom: 15
},
divider: {
backgroundColor: 'grey'
}
};
export default class Comment extends React.Component {
render() {
return (
<Paper zDepth={5} rounded={false} style={styles.paper}>
<div>
<List>
<CommentItem />
</List>
<Divider style={styles.divider}/>
<CommentForm/>
</div>
</Paper>
);
}
}