import React from 'react'; import axios from 'axios'; import { ScrollView, Image, View, RefreshControl, } from 'react-native'; import { RkCard, RkText, RkStyleSheet, } from 'react-native-ui-kitten'; import { Avatar, SocialBar, } from '../../components'; import NavigationType from '../../config/navigation/propTypes'; import {HOST} from '../../constants' export class Article extends React.Component { state = { article: {}, mounted: false, refreshing: false, }; static propTypes = { navigation: NavigationType.isRequired, }; static navigationOptions = { title: 'Current problem'.toUpperCase(), }; componentWillMount() { this.makeRemoteRequest() } makeRemoteRequest = () => { const articleId = this.props.navigation.getParam('id', 1); console.log(articleId); axios.get(`${HOST}/api/articles/${articleId}`) .then(res => { this.setState({ article: res.data, mounted: true, refreshing: false, }); console.log(this.state.article); }); }; handleRefresh = () => { this.setState({ refreshing: true, }, () => { setTimeout(() => { this.makeRemoteRequest() }, 500) }) }; render() { if (this.state.mounted) { return ( }> {this.state.article.title} {this.state.article.text} ); } return null; } } const styles = RkStyleSheet.create(theme => ({ root: { backgroundColor: theme.colors.screen.base, }, title: { marginBottom: 5, }, }));