Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import {
- Image,
- StyleSheet,
- Text,
- View,
- } from 'react-native';
- export default class App extends Component {
- constructor(props){
- super(props);
- this.state = {
- photos: '',
- titles: ''
- };
- }
- componentWillMount(){
- this.fetchData();
- }
- fetchData = async () => {
- let response = await fetch('http://jsonplaceholder.typicode.com/photos/1');
- let json = await response.json();
- this.setState({titles: json.title, photos: json.url.replace('http','https')});
- };
- render() {
- console.log(this.state.photos)
- return (
- <View style={styles.container}>
- <Image
- source={{uri: this.state.photos}}
- style={{height: 600, width: 600}}
- resizeMode= 'cover'
- />
- <Text>
- Title: {this.state.titles}
- </Text>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: '#ecf0f1',
- }
- });
Add Comment
Please, Sign In to add comment