I'm new to React
and React native
and am trying to retrieve data from an API
and then render it but I seem to be running into problems.
I can grab the data from the API
alright, but when I try and render
it I'm getting all sorts of errors.
Essentially all I'm trying to do is render the photos that are returned from the API. Should be simple right? Would appreciate anyone who can point me in the right track.
I'm getting errors like:
undefined is not an object (evaluating 'this.props.photos') in RenderPhotos_render
I may have jumped into React Native
too early...So excuse my lack of knowledge!
var AwesomeProject = React.createClass({
getInitialState: function() {
return {
isLoading: true,
photos: this.props.photos
};
},
componentWillMount: function(){
fetch("http://localhost:3000/api/photos/", {
method: "GET",
headers: {
"x-access-token":"xxxxx",
"x-key":"xxxx"
},
})
.then((response) => response.json())
.then((responseData) => {
AlertIOS.alert(
"GET Response",
"Search Query -> " + JSON.stringify(responseData)
)
this.setState({
isLoading: false
});
this.setState({
photos: JSON.stringify(responseData)
});
})
.done();
},
render: function() {
if(this.state.isLoading){
return <View><Text>Loading...</Text></View>
}
return (
<RenderPhotos photos={this.props.photos}/>
);
},
});
var RenderPhotos = React.createClass({
getInitialState: function() {
return {
photos: this.props.photos
};
},
render: function(){
var photos = Photos;
return (
<View>
<Text> {this.props.photos[0]} </Text>
</View>
)
}
});