Guest User

Untitled

a guest
Aug 24th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useState, useEffect} from "react";
  2. import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
  3.  
  4. const App = () => {
  5.     const [hasError, setErrors] = useState(false);
  6.     const [state, setState] = useState({});
  7.  
  8.     useEffect(() => {
  9.         async function fetchData() {
  10.             const res = await fetch("https://oauth.vk.com/authorize?client_id=7563861&display=mobile&redirect_uri=https://auth.expo.io/@laneboyandrew/beautifulPlaces&response_type=token&v=5.92");
  11.             res
  12.                 .json()
  13.                 .then(res => setState(res))
  14.                 .catch(err => setErrors(err));
  15.  
  16.             if (state.result.type === 'success') {
  17.                 const res = await fetch('https://api.vk.com/method/users.get?v=5.92&access_token=' + state.result.params.access_token);
  18.                 res
  19.                     .json()
  20.                     .then(res => setState(res))
  21.                     .catch(err => setErrors(err));
  22.             }
  23.         }
  24.         fetchData();
  25.     });
  26.  
  27.     return (
  28.         <View>
  29.             <Text>{JSON.stringify(state)}</Text>
  30.  
  31.             <Text> Has error: {JSON.stringify(hasError)}</Text>
  32.         </View>
  33.     );
  34. };
  35. export default App;
Add Comment
Please, Sign In to add comment