Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Syntax Eror: 'return' outside of function [closed]

$
0
0

I've been dealing with the React Native for a short time, I got such an error and I can't solve it, I would be very happy if someone could help.

I think the problem is caused by the syntax or the AsyncStorage.

import React from "react";import { StyleSheet, } from "react-native";import { NavigationContainer } from "@react-navigation/native";import { createNativeStackNavigator } from "@react-navigation/native-stack";import { StatusBar } from "expo-status-bar";import Login from './screens/Login';import AskTesti from "./screens/AskTesti";import AskTestiSakası from "./screens/AskTestiSakası";import KarakterTesti from "./screens/KarakterTesti";import KendiAskTesti from "./screens/KendiAskTesti";import AskTestiDetay from "./screens/AskTestiDetay";import KarakterDetay from "./screens/KarakterDetay";import  { useCallback, useEffect, useState } from 'react';import * as SplashScreen from 'expo-splash-screen';import Appintro from '/Users/alperenbulut/Desktop/asktesti/screens/Appintro.js';import AsyncStorage from "@react-native-async-storage/async-storage";const Stack = createNativeStackNavigator();export default function App () {  const [appIsReady, setAppIsReady] = useState(false);  useEffect(() => {    async function prepare() {      try {        await new Promise(resolve => setTimeout(resolve, 1000));      } catch (e) {        console.warn(e);      } finally {        setAppIsReady(true);      }    }    prepare();  }, []);  const onLayoutRootView = useCallback(async () => {    if (appIsReady) {      await SplashScreen.hideAsync();    }  }, [appIsReady]);  if (!appIsReady) {    return null;  }}  // ayrım noktası  const [isFirstLaunch, setIsFirstLaunch] = React.useState(null);  useEffect(() => {    AsyncStorage.getItem('alreadyLaunched').then(value => {      if(value == null){        AsyncStorage.setItem('alreadyLaunched', 'true');        setIsFirstLaunch(true);      } else {        setIsFirstLaunch(false);      }    });  },[]);  if (isFirstLaunch === null ) {    return null;  } else if (isFirstLaunch === true ) {      return (<NavigationContainer><StatusBar style='light'/><Stack.Navigator      screenOptions={{        headerTintColor: 'white',        headerShown: false,        headerStyle: { backgroundColor: '#040f2d' },      }}><Stack.Screen name='Appintro' component={Appintro} options={{headerTitle:'' }} /><Stack.Screen name='Login' component={Login} options={{headerTitle:'' }} /><Stack.Screen name='AskTesti' component={AskTesti} options={{headerTitle: ''} } /><Stack.Screen name='AskTestiSakası' component={AskTestiSakası}options={{headerTitle: ''}}/><Stack.Screen name='KarakterTesti' component={KarakterTesti}options={{headerTitle: ''}}   /><Stack.Screen name='KarakterDetay'  component={KarakterDetay} options={{headerTitle: ''}} initialParams={{isim:''}} /><Stack.Screen name='KendiAskTesti' component={KendiAskTesti}options={{headerTitle: ''}}/><Stack.Screen name='AskTestiDetay' component={AskTestiDetay} options={{headerTitle: ''}} initialParams={{firstname: '', secondname: '', yorum:''}} /></Stack.Navigator></NavigationContainer>      );  } else {   return <Login/>;  }const styles = StyleSheet.create({  ads:{    width:'100%',    height:50,    backgroundColor:'#C7C7C7',    justifyContent:'center',    alignContent:'center',    alignItems:'center',  }});

Here is my code screenshot


Viewing all articles
Browse latest Browse all 6287

Trending Articles