Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {Text, View, Image} from 'react-native';
  3.  
  4. class Janta extends Component {
  5.   constructor(props){
  6.     super(props);
  7.     this.state={comida:props.comida};
  8.     var comidas=['Pizza', 'Lasanha','Burger','Sopa','arroz'];
  9.  
  10.     setInterval(()=>{
  11.       this.setState(previousState=>{
  12.         var n = Math.floor(Math.random() * comidas.length);
  13.         return {comida: comidas[n]};
  14.       });
  15.     },1000);
  16.  
  17.   }
  18.  
  19.   render() {
  20.     return(
  21.       <View style={{paddingTop:20}}>
  22.         <Text style={{textAlign:'center', fontWeight:'bold', fontSize:20}}>Hoje você vai jantar: </Text>
  23.         <Text style={{textAlign:'center', fontSize:20}}>{this.state.comida}</Text>
  24.       </View>
  25.  
  26.       );
  27.  
  28.   }
  29. }
  30.  
  31. export default class PrimeiroProjeto extends Component {
  32.   render() {
  33.  
  34.     return (
  35.       <View style={{paddingTop:20}}>
  36.         <Janta comida='Bolacha'/>
  37.       </View>
  38.     );
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement